scaffold

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package scaffold is the Stage-1 namespace for scaffolding, recipes, patterns, skills, and few-shot types. See ../REFACTOR_PLAN.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPattern

func FormatPattern(p *PromptPattern) string

FormatPattern returns a human-readable string representation of a pattern.

func FormatSkill

func FormatSkill(skill *Skill) string

FormatSkill produces a human-readable representation of a skill.

func RenderTree

func RenderTree(files []string) string

RenderTree creates an ASCII tree visualization from a list of file paths.

Types

type FewShotExample

type FewShotExample struct {
	Prompt    string    `json:"prompt"`
	Response  string    `json:"response"`
	TaskType  string    `json:"task_type"`
	Quality   float64   `json:"quality"` // 0-1, based on whether output was kept
	CreatedAt time.Time `json:"created_at"`
	UsedCount int       `json:"used_count"`
}

FewShotExample is a recorded successful interaction.

type FewShotStore

type FewShotStore struct {
	// contains filtered or unexported fields
}

FewShotStore collects successful (prompt, response) pairs and injects the most relevant as few-shot examples into the system prompt.

func NewFewShotStore

func NewFewShotStore() *FewShotStore

NewFewShotStore creates a store backed by ~/.hawk/fewshot.json.

func (*FewShotStore) FormatForPrompt

func (fs *FewShotStore) FormatForPrompt(prompt string) string

FormatForPrompt returns few-shot examples formatted for system prompt injection.

func (*FewShotStore) Record

func (fs *FewShotStore) Record(prompt, response, taskType string)

Record saves a successful interaction as a potential few-shot example.

func (*FewShotStore) Retrieve

func (fs *FewShotStore) Retrieve(prompt string, topK int) []FewShotExample

Retrieve finds the most relevant few-shot examples for a given prompt.

type PatternLibrary

type PatternLibrary struct {
	Patterns map[string]*PromptPattern
	Dir      string
	// contains filtered or unexported fields
}

PatternLibrary holds a collection of prompt patterns and supports loading, searching, and chaining them.

func NewPatternLibrary

func NewPatternLibrary(dir string) *PatternLibrary

NewPatternLibrary creates a new PatternLibrary with the given directory for custom pattern storage.

func (*PatternLibrary) Apply

func (pl *PatternLibrary) Apply(patternName string, input string) (string, string, error)

Apply resolves a pattern by name and injects the input into its template. Returns the system prompt, composed user prompt, and any error.

func (*PatternLibrary) Chain

func (pl *PatternLibrary) Chain(patterns []string, input string) []string

Chain applies multiple patterns sequentially, where the output prompt of one becomes the input for the next. Returns the list of user prompts generated at each step.

func (*PatternLibrary) Get

func (pl *PatternLibrary) Get(name string) *PromptPattern

Get retrieves a pattern by name. Returns nil if not found.

func (*PatternLibrary) ListByTag

func (pl *PatternLibrary) ListByTag(tag string) []*PromptPattern

ListByTag returns all patterns that have the specified tag.

func (*PatternLibrary) LoadBuiltins

func (pl *PatternLibrary) LoadBuiltins()

LoadBuiltins populates the library with built-in prompt patterns.

func (*PatternLibrary) LoadFromDir

func (pl *PatternLibrary) LoadFromDir(dir string) error

LoadFromDir loads custom patterns from markdown files with YAML frontmatter in the specified directory. Each .md file is parsed for frontmatter fields (name, description, system_prompt, output_format, tags, version, author) and the body becomes the UserTemplate.

func (*PatternLibrary) Register

func (pl *PatternLibrary) Register(pattern *PromptPattern)

Register adds a new pattern to the library. If a pattern with the same name exists, it is overwritten.

func (*PatternLibrary) Remove

func (pl *PatternLibrary) Remove(name string)

Remove deletes a pattern from the library by name.

func (*PatternLibrary) Search

func (pl *PatternLibrary) Search(query string) []*PromptPattern

Search performs a fuzzy search across pattern names, descriptions, and tags. Returns all patterns that match the query substring (case-insensitive).

type PromptPattern

type PromptPattern struct {
	Name         string
	Description  string
	SystemPrompt string
	UserTemplate string
	OutputFormat string
	Tags         []string
	Version      string
	Author       string
}

PromptPattern represents a composable, reusable prompt pattern for common tasks.

type Recipe

type Recipe struct {
	ID          string                 `json:"id,omitempty"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Prompt      string                 `json:"prompt"`
	Tools       []string               `json:"tools"`
	Model       string                 `json:"model"`
	Provider    string                 `json:"provider"`
	Settings    map[string]interface{} `json:"settings,omitempty"`
	Author      string                 `json:"author"`
	Version     string                 `json:"version"`
	CreatedAt   time.Time              `json:"created_at"`
}

Recipe represents a shareable task recipe that captures instructions, tools, settings, and metadata for one-click execution via deeplinks.

type RecipeRegistry

type RecipeRegistry struct {
	Recipes map[string]*Recipe
	Dir     string
	// contains filtered or unexported fields
}

RecipeRegistry manages a collection of recipes with thread-safe access.

func NewRecipeRegistry

func NewRecipeRegistry(dir string) *RecipeRegistry

NewRecipeRegistry creates a new RecipeRegistry that stores recipes in dir.

func (*RecipeRegistry) Create

func (r *RecipeRegistry) Create(recipe *Recipe) string

Create adds a recipe to the registry and returns its generated ID.

func (*RecipeRegistry) Decode

func (r *RecipeRegistry) Decode(deeplink string) (*Recipe, error)

Decode parses a hawk:// deeplink URL, base64url-decodes the payload, and deserializes it into a Recipe.

func (*RecipeRegistry) Encode

func (r *RecipeRegistry) Encode(recipe *Recipe) string

Encode serializes a recipe to JSON, base64url-encodes it, and returns a hawk:// deeplink URL.

func (*RecipeRegistry) Execute

func (r *RecipeRegistry) Execute(ctx context.Context, recipe *Recipe, execFn func(context.Context, string) (string, error)) (string, error)

Execute applies the recipe settings and runs the prompt using the provided execution function. The execFn receives the context and the recipe prompt, and returns the output or an error.

func (*RecipeRegistry) FormatRecipe

func (r *RecipeRegistry) FormatRecipe(recipe *Recipe) string

FormatRecipe returns a human-readable formatted string representation of the recipe.

func (*RecipeRegistry) Get

func (r *RecipeRegistry) Get(id string) *Recipe

Get returns a recipe by ID, or nil if not found.

func (*RecipeRegistry) ImportFromURL

func (r *RecipeRegistry) ImportFromURL(url string) (*Recipe, error)

ImportFromURL decodes a hawk:// deeplink URL and imports the recipe into the registry.

func (*RecipeRegistry) List

func (r *RecipeRegistry) List() []*Recipe

List returns all recipes in the registry.

func (*RecipeRegistry) Load

func (r *RecipeRegistry) Load() error

Load reads recipes from the registry's directory on disk.

func (*RecipeRegistry) Save

func (r *RecipeRegistry) Save() error

Save persists all recipes in the registry to disk as a JSON file.

func (*RecipeRegistry) Share

func (r *RecipeRegistry) Share(recipe *Recipe) string

Share generates a compact shareable deeplink URL for the recipe.

func (*RecipeRegistry) Validate

func (r *RecipeRegistry) Validate(recipe *Recipe) []string

Validate checks a recipe for required fields and returns a list of validation error messages. An empty slice means the recipe is valid.

type Scaffolder

type Scaffolder struct {
	Templates   map[string]*Template
	TemplateDir string
	// contains filtered or unexported fields
}

Scaffolder manages templates and generates projects.

func NewScaffolder

func NewScaffolder() *Scaffolder

NewScaffolder creates a new Scaffolder with built-in templates.

func (*Scaffolder) Generate

func (s *Scaffolder) Generate(templateName string, vars map[string]string, outputDir string) error

Generate creates a project from a template.

func (*Scaffolder) ListTemplates

func (s *Scaffolder) ListTemplates() []*Template

ListTemplates returns all registered templates sorted by name.

func (*Scaffolder) LoadTemplate

func (s *Scaffolder) LoadTemplate(path string) (*Template, error)

LoadTemplate loads a template from a JSON file.

func (*Scaffolder) Preview

func (s *Scaffolder) Preview(templateName string, vars map[string]string) string

Preview shows what would be created without actually creating files.

func (*Scaffolder) RegisterTemplate

func (s *Scaffolder) RegisterTemplate(t *Template)

RegisterTemplate adds a new template to the scaffolder.

func (*Scaffolder) ValidateVars

func (s *Scaffolder) ValidateVars(tmpl *Template, vars map[string]string) []string

ValidateVars checks that required variables are provided and choices are valid.

type Skill

type Skill struct {
	ID          string      `json:"id"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Steps       []SkillStep `json:"steps"`
	Tags        []string    `json:"tags"`
	Language    string      `json:"language"`
	SuccessRate float64     `json:"success_rate"`
	UsageCount  int         `json:"usage_count"`
	CreatedAt   time.Time   `json:"created_at"`
	Author      string      `json:"author"` // "agent", "user", "community"
}

Skill represents a reusable agent skill — a learned task sequence that can be replayed.

type SkillRegistry

type SkillRegistry struct {
	Skills map[string]*Skill `json:"skills"`
	Dir    string            `json:"dir"`
	// contains filtered or unexported fields
}

SkillRegistry manages a collection of reusable skills.

func NewSkillRegistry

func NewSkillRegistry(dir string) *SkillRegistry

NewSkillRegistry creates a new SkillRegistry backed by the given directory.

func (*SkillRegistry) Execute

func (r *SkillRegistry) Execute(ctx context.Context, skillID string, vars map[string]string, execFn func(string) (string, error)) (*SkillResult, error)

Execute runs a skill step-by-step, substituting variables and tracking results.

func (*SkillRegistry) Get

func (r *SkillRegistry) Get(id string) *Skill

Get retrieves a skill by ID.

func (*SkillRegistry) LearnFromSession

func (r *SkillRegistry) LearnFromSession(goal string, toolCalls []string, outcome string) *Skill

LearnFromSession extracts a reusable skill from a successful session.

func (*SkillRegistry) ListByTag

func (r *SkillRegistry) ListByTag(tag string) []*Skill

ListByTag returns all skills with the given tag.

func (*SkillRegistry) Load

func (r *SkillRegistry) Load() error

Load reads the registry from disk.

func (*SkillRegistry) Register

func (r *SkillRegistry) Register(skill *Skill) error

Register adds a skill to the registry.

func (*SkillRegistry) Remove

func (r *SkillRegistry) Remove(id string) error

Remove deletes a skill from the registry.

func (*SkillRegistry) Save

func (r *SkillRegistry) Save() error

Save persists the registry to disk as JSON.

func (*SkillRegistry) Search

func (r *SkillRegistry) Search(query string, tags []string) []*Skill

Search finds skills matching the query and/or tags, ranked by relevance and success rate.

func (*SkillRegistry) UpdateStats

func (r *SkillRegistry) UpdateStats(id string, success bool)

UpdateStats updates the success rate and usage count for a skill.

type SkillResult

type SkillResult struct {
	SkillID        string        `json:"skill_id"`
	Success        bool          `json:"success"`
	StepsCompleted int           `json:"steps_completed"`
	TotalSteps     int           `json:"total_steps"`
	Duration       time.Duration `json:"duration"`
	Outputs        []string      `json:"outputs"`
}

SkillResult captures the outcome of executing a skill.

type SkillStep

type SkillStep struct {
	Order           int    `json:"order"`
	Action          string `json:"action"` // "prompt", "tool_call", "check"
	Content         string `json:"content"`
	ToolName        string `json:"tool_name,omitempty"`
	ExpectedOutcome string `json:"expected_outcome,omitempty"`
	Fallback        string `json:"fallback,omitempty"`
}

SkillStep represents a single step in a skill sequence.

type Template

type Template struct {
	Name        string             `json:"name"`
	Description string             `json:"description"`
	Language    string             `json:"language"`
	Framework   string             `json:"framework"`
	Files       []TemplateFile     `json:"files"`
	Variables   []TemplateVariable `json:"variables"`
	PostCreate  []string           `json:"post_create"`
}

Template defines a project template for scaffolding.

type TemplateFile

type TemplateFile struct {
	Path      string      `json:"path"`
	Content   string      `json:"content"`
	Mode      os.FileMode `json:"mode"`
	Condition string      `json:"condition"`
}

TemplateFile defines a single file within a template.

type TemplateVariable

type TemplateVariable struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Default     string   `json:"default"`
	Required    bool     `json:"required"`
	Type        string   `json:"type"` // "string", "bool", "choice"
	Choices     []string `json:"choices,omitempty"`
}

TemplateVariable defines a variable used in template rendering.

Jump to

Keyboard shortcuts

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