mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-13 19:20:06 +00:00
017eb99d44
Add user-defined prompt templates that expand into full prompts with
shell-style argument substitution.
Features:
- Templates loaded from ~/.kit/prompts/*.md and .kit/prompts/*.md
- YAML frontmatter support for description
- Argument placeholders: $1, $2, $@, $ARGUMENTS, ${@:N}, ${@:N:L}
- Autocomplete integration (templates appear as /name commands)
- CLI flags: --prompt-template and --no-prompt-templates
- First-match-wins collision handling with logged diagnostics
Example template:
---
description: Review code for issues
---
Review the following code for bugs and security issues.
Focus on $1 specifically.
Usage: /review error handling
26 lines
642 B
Go
26 lines
642 B
Go
package prompts
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
// frontmatterSep is the YAML frontmatter delimiter.
|
|
const frontmatterSep = "---"
|
|
|
|
// Frontmatter represents the YAML frontmatter in a prompt template file.
|
|
type Frontmatter struct {
|
|
// Description summarises what this template provides.
|
|
Description string `yaml:"description"`
|
|
}
|
|
|
|
// ParseFrontmatter parses YAML frontmatter content into a Frontmatter struct.
|
|
func ParseFrontmatter(content string) (*Frontmatter, error) {
|
|
var fm Frontmatter
|
|
if err := yaml.Unmarshal([]byte(content), &fm); err != nil {
|
|
return nil, fmt.Errorf("parsing frontmatter: %w", err)
|
|
}
|
|
return &fm, nil
|
|
}
|