Documentation
¶
Index ¶
- func Deduplicate(templates []*PromptTemplate) ([]*PromptTemplate, []Diagnostic)
- func LoadAll(opts LoadOptions) ([]*PromptTemplate, []Diagnostic, error)
- func ParseCommandArgs(input string) []string
- func SubstituteArgs(content string, args []string) string
- type Diagnostic
- type Frontmatter
- type LoadOptions
- type PromptTemplate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deduplicate ¶
func Deduplicate(templates []*PromptTemplate) ([]*PromptTemplate, []Diagnostic)
Deduplicate removes duplicate templates by name, keeping the first occurrence. It returns the deduplicated list and diagnostics for any collisions. This is a standalone function for when you need to deduplicate an existing list.
func LoadAll ¶
func LoadAll(opts LoadOptions) ([]*PromptTemplate, []Diagnostic, error)
LoadAll discovers and loads all prompt templates from standard locations and any extra paths. Templates are loaded in order of precedence (lowest to highest), with later templates overriding earlier ones of the same name.
Discovery paths searched in order:
- Default templates (if IncludeDefaults)
- ~/.kit/prompts/ (global user templates)
- .kit/prompts/ (project-local templates)
- ConfigPaths (from configuration)
- ExtraPaths (explicit paths, highest precedence)
func ParseCommandArgs ¶
ParseCommandArgs splits a command line into arguments respecting quotes. It handles single quotes, double quotes, and backslash escaping.
func SubstituteArgs ¶
SubstituteArgs replaces argument placeholders in content with values from args. Supported placeholders:
- $N, ${N} - the Nth argument (1-indexed)
- $@, $+, $ARGUMENTS, ${ARGUMENTS} - all arguments joined with spaces
- ${@:N} - arguments from index N onwards (0-indexed)
- ${@:N:L} - L arguments starting from index N (0-indexed)
Types ¶
type Diagnostic ¶
type Diagnostic struct {
// Name is the template name that had a collision.
Name string
// KeptPath is the path of the template that was kept (higher precedence).
KeptPath string
// DroppedPath is the path of the template that was dropped.
DroppedPath string
// Reason explains why the collision occurred.
Reason string
}
Diagnostic reports a template collision or loading issue.
type Frontmatter ¶
type Frontmatter struct {
// Description summarises what this template provides.
Description string `yaml:"description"`
}
Frontmatter represents the YAML frontmatter in a prompt template file.
func ParseFrontmatter ¶
func ParseFrontmatter(content string) (*Frontmatter, error)
ParseFrontmatter parses YAML frontmatter content into a Frontmatter struct.
type LoadOptions ¶
type LoadOptions struct {
// Cwd is the current working directory for project-local discovery.
// If empty, the current working directory is used.
Cwd string
// HomeDir is the user's home directory. If empty, os.UserHomeDir() is used.
HomeDir string
// ExtraPaths are additional explicit paths to search for templates.
ExtraPaths []string
// ConfigPaths are paths from configuration files to search.
ConfigPaths []string
// IncludeDefaults determines whether to include built-in default templates.
IncludeDefaults bool
}
LoadOptions configures how templates are discovered and loaded.
type PromptTemplate ¶
type PromptTemplate struct {
// Name is the human-readable identifier for this template.
Name string
// Description summarises what this template provides.
Description string
// Content is the raw template text with placeholders.
Content string
// Source indicates where the template was loaded from (e.g., "default", "user").
Source string
// FilePath is the absolute filesystem path the template was loaded from.
FilePath string
}
PromptTemplate is a named prompt template with shell-style argument placeholders. It supports Pi-style $1, $2, $@, $+, $ARGUMENTS, ${@:N}, ${@:N:L} syntax.
func LoadFromDir ¶
func LoadFromDir(dir string) ([]*PromptTemplate, error)
LoadFromDir scans a directory for .md files and loads them as templates. It looks for *.md files directly in the directory. Files that fail to parse are logged and skipped.
func ParseTemplate ¶
func ParseTemplate(path string) (*PromptTemplate, error)
ParseTemplate reads a template from a file. The template name is derived from the filename (without extension). If the file contains YAML frontmatter, the description is extracted from it.
func (*PromptTemplate) Expand ¶
func (t *PromptTemplate) Expand(argsInput string) string
Expand substitutes arguments into the template content and returns the result. It first parses args from the input string, then substitutes them into the template.
func (*PromptTemplate) ExpandWithArgs ¶
func (t *PromptTemplate) ExpandWithArgs(args []string) string
ExpandWithArgs substitutes the provided arguments into the template content.
func (*PromptTemplate) HasArgPlaceholders ¶ added in v0.49.0
func (t *PromptTemplate) HasArgPlaceholders() bool
HasArgPlaceholders reports whether the template content contains any argument placeholders ($1, $@, $ARGUMENTS, ${@:...}, etc.). Placeholders inside fenced code blocks and inline code spans are ignored.
func (*PromptTemplate) RequiredArgs ¶ added in v0.49.0
func (t *PromptTemplate) RequiredArgs() int
RequiredArgs returns the number of positional arguments the template expects. This is determined by the highest $N or ${N} placeholder found in the content (1-indexed, so $2 means 2 args required). The $+ placeholder (required variadic) ensures at least 1. Optional wildcards ($@, $ARGUMENTS) do not contribute to the count.