prompts

package
v0.70.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GlobalDir added in v0.70.0

func GlobalDir() string

GlobalDir returns the XDG-aligned global prompts directory, respecting $XDG_CONFIG_HOME. Defaults to ~/.config/kit/prompts/. Returns an empty string if the user's home directory cannot be resolved.

This is the canonical location for user-wide prompt templates and aligns with the discovery paths used for extensions ($XDG_CONFIG_HOME/kit/extensions/) and skills ($XDG_CONFIG_HOME/kit/skills/).

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 (highest to lowest); the first source to define a given name wins, later definitions of the same name are dropped with a diagnostic.

Discovery paths searched in order:

  1. Default templates (if IncludeDefaults)
  2. ~/.kit/prompts/ (legacy global)
  3. $XDG_CONFIG_HOME/kit/prompts/ (XDG global, default ~/.config/kit/prompts/)
  4. <cwd>/.kit/prompts/ (project-local templates)
  5. ConfigPaths (from configuration)
  6. ExtraPaths (explicit paths, lowest 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.

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.

Jump to

Keyboard shortcuts

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