prompts

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

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:

  1. Default templates (if IncludeDefaults)
  2. ~/.kit/prompts/ (global user templates)
  3. .kit/prompts/ (project-local templates)
  4. ConfigPaths (from configuration)
  5. ExtraPaths (explicit paths, highest precedence)

func ParseCommandArgs

func ParseCommandArgs(input string) []string

ParseCommandArgs splits a command line into arguments respecting quotes. It handles single quotes, double quotes, and backslash escaping.

func SubstituteArgs

func SubstituteArgs(content string, args []string) string

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.

Jump to

Keyboard shortcuts

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