actions

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package actions handles staghorn action parsing, registry, and rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewActionTemplate

func NewActionTemplate(name, description string) string

NewActionTemplate returns a template for creating a new action.

func ParseArgs

func ParseArgs(rawArgs []string) (map[string]string, error)

ParseArgs parses command-line style arguments into a map. Supports formats:

  • --name value
  • --name=value
  • name=value

Types

type Action

type Action struct {
	Frontmatter
	Body     string // Markdown content after frontmatter
	Source   Source // Where this action came from
	FilePath string // Path to the action file
}

Action represents a staghorn action.

func LoadFromDirectory

func LoadFromDirectory(dir string, source Source) ([]*Action, error)

LoadFromDirectory loads all actions from a directory.

func Parse

func Parse(content string, source Source, filePath string) (*Action, error)

Parse parses an action from markdown content.

func ParseFile

func ParseFile(path string, source Source) (*Action, error)

ParseFile parses an action from a file.

func (*Action) ExtractVariables

func (a *Action) ExtractVariables() []string

ExtractVariables returns all variable names used in the action body.

func (*Action) FormatArgsHelp

func (a *Action) FormatArgsHelp() string

FormatArgsHelp formats the arguments help text for an action.

func (*Action) GetArg

func (a *Action) GetArg(name string) *Arg

GetArg returns an argument by name.

func (*Action) GetArgWithDefault

func (a *Action) GetArgWithDefault(args map[string]string, name string) string

GetArgWithDefault returns the argument value or its default.

func (*Action) HasArg

func (a *Action) HasArg(name string) bool

HasArg checks if the action has a specific argument.

func (*Action) Render

func (a *Action) Render(args map[string]string) (string, error)

Render renders an action's body with the provided arguments. Uses a simple {{varname}} syntax for user-friendliness.

func (*Action) RenderWithValidation

func (a *Action) RenderWithValidation(args map[string]string) (string, []string, error)

RenderWithValidation renders and also returns warnings for undefined variables.

func (*Action) ValidateArgs

func (a *Action) ValidateArgs(args map[string]string) error

ValidateArgs validates provided arguments against the action's definition.

type Arg

type Arg struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description"`
	Default     string   `yaml:"default"`
	Options     []string `yaml:"options,omitempty"` // Valid options if constrained
	Required    bool     `yaml:"required"`
}

Arg defines an action argument.

type Frontmatter

type Frontmatter struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description"`
	Tags        []string `yaml:"tags,omitempty"`
	Args        []Arg    `yaml:"args,omitempty"`
}

Frontmatter contains the YAML frontmatter of an action.

func ReadFrontmatterOnly

func ReadFrontmatterOnly(path string) (*Frontmatter, error)

ReadFrontmatterOnly reads just the frontmatter without loading the full body. Useful for listing actions without loading all content into memory.

type Registry

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

Registry manages actions from multiple sources with precedence handling. Precedence (highest to lowest): project > personal > team

func LoadRegistry

func LoadRegistry(teamDir, personalDir, projectDir string) (*Registry, error)

LoadRegistry creates a registry by loading actions from all sources.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty action registry.

func (*Registry) Add

func (r *Registry) Add(action *Action)

Add adds an action to the registry. If an action with the same name exists from a lower precedence source, it's overridden.

func (*Registry) AddAll

func (r *Registry) AddAll(actions []*Action)

AddAll adds multiple actions to the registry.

func (*Registry) All

func (r *Registry) All() []*Action

All returns all unique actions (highest precedence version of each).

func (*Registry) BySource

func (r *Registry) BySource(source Source) []*Action

BySource returns all actions from a specific source.

func (*Registry) ByTag

func (r *Registry) ByTag(tag string) []*Action

ByTag returns all actions that have a specific tag.

func (*Registry) Count

func (r *Registry) Count() int

Count returns the total number of unique actions.

func (*Registry) CountBySource

func (r *Registry) CountBySource() map[Source]int

CountBySource returns counts per source.

func (*Registry) Get

func (r *Registry) Get(name string) *Action

Get returns an action by name (highest precedence version).

func (*Registry) GetAllVersions

func (r *Registry) GetAllVersions(name string) []*Action

GetAllVersions returns all versions of an action across sources.

func (*Registry) IsOverridden

func (r *Registry) IsOverridden(name string, source Source) bool

IsOverridden checks if an action from a lower source is overridden.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns all action names.

type Source

type Source string

Source indicates where an action came from.

const (
	SourceTeam     Source = "team"
	SourcePersonal Source = "personal"
	SourceProject  Source = "project"
)

func (Source) Label

func (s Source) Label() string

SourceLabel returns a human-readable label for the source.

Jump to

Keyboard shortcuts

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