skill

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("skill not found")
	ErrModelInvocationDenied = errors.New("skill cannot be invoked by the model")
	ErrUserInvocationDenied  = errors.New("skill cannot be invoked by the user")
)

Functions

func ExpandArgs

func ExpandArgs(body, rawArgs string) string

func ExpandShellInjections

func ExpandShellInjections(body string) string

func ExpandVars

func ExpandVars(body, skillDir, sessionID string) string

func FirstLine

func FirstLine(s string, maxLen int) string

func NormalizeAgentType

func NormalizeAgentType(agent string) string

func NormalizeName

func NormalizeName(name string) string

func RenderListing

func RenderListing(skills []Spec, opts ListingOptions) string

RenderListing renders the skill listing that goes into the cached system block. Two-phase on purpose:

  1. walk `skills` in the caller's order (OrderForPrompt's usage ranking) and keep entries until the char budget runs out — the most relevant skills win the budget;
  2. sort the survivors by a time-independent key and render.

Phase 2 is what makes the output byte-stable. Usage scores decay with wall time, so rendering in ranking order would reshuffle the block on every rebuild and invalidate the prompt cache prefix for no semantic gain. The output only changes when the surviving SET changes, which needs the catalog to exceed the budget AND a ranking swap across the cutoff.

func SourceAllowsPrivilegedFields

func SourceAllowsPrivilegedFields(source string) bool

func SourceAllowsShellExecution

func SourceAllowsShellExecution(source string) bool

func StripFrontmatter

func StripFrontmatter(content string) string

func ValidName

func ValidName(name string) bool

func WrapPrompt

func WrapPrompt(spec Spec, body string) string

Types

type Catalog

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

func NewCatalog

func NewCatalog(cwd string, baseSpecs []Spec, extraDirs ...DirSource) *Catalog

func NewStaticCatalog

func NewStaticCatalog(specs []Spec) *Catalog

func (*Catalog) Get

func (c *Catalog) Get(name string) (Spec, bool)

func (*Catalog) List

func (c *Catalog) List() []Spec

func (*Catalog) Reload

func (c *Catalog) Reload()

func (*Catalog) Retarget added in v0.3.0

func (c *Catalog) Retarget(cwd string)

Retarget points the catalog at a new workspace root. Only the activation check (Spec.Paths, resolved against cwd) depends on it — the specs themselves come from plugin contributions and configured directories, so no reload is needed. Called on a worktree enter/exit: leaving the boot cwd here would keep deciding which skills apply from the workspace the session has left.

type Delta

type Delta struct {
	AllowedTools  []string
	ModelOverride string
	Effort        string
	Paths         []string
}

type DirSource

type DirSource struct {
	Path   string
	Source string
}

type GetPromptFn

type GetPromptFn func(ctx context.Context, args string, sessionID string) (string, error)

type InvocationMode

type InvocationMode string
const (
	ModeInline InvocationMode = "inline"
	ModeFork   InvocationMode = "fork"
)

type InvocationResult

type InvocationResult struct {
	Spec       Spec
	Mode       InvocationMode
	PromptText string
	Agent      string
	Delta      Delta
}

func ProcessInvocation

func ProcessInvocation(ctx context.Context, catalog *Catalog, in InvokeInput) (*InvocationResult, error)

type InvocationSource

type InvocationSource string
const (
	SourceModel InvocationSource = "model"
	SourceUser  InvocationSource = "user"
)

type InvokeInput

type InvokeInput struct {
	Name      string
	Args      string
	SessionID string
	Source    InvocationSource
}

type ListingOptions

type ListingOptions struct {
	CharBudget       int
	MaxLineChars     int
	MaxWhenChars     int
	IncludeWhenToUse bool
}

func DefaultListingOptions

func DefaultListingOptions() ListingOptions

type Spec

type Spec struct {
	Name        string
	Description string
	WhenToUse   string
	Version     string

	FilePath string
	BaseDir  string
	Source   string

	DisableModelInvocation bool
	DisableUserInvocation  bool

	ArgumentHint  string
	ArgumentNames []string

	Context string
	Agent   string
	Model   string
	Effort  string

	AllowedTools []string
	Paths        []string

	HasExplicitDescription bool
	FrontmatterKeys        []string

	GetPrompt GetPromptFn
}

func BundledSpecs

func BundledSpecs(cwd string) []Spec

func LoadFromDir

func LoadFromDir(dir, source string) []Spec

func OrderForPrompt

func OrderForPrompt(skills []Spec, cwd string, usage map[string]float64) []Spec

OrderForPrompt ranks skills by relevance (applicable → usage → source → name). The ranking decides which skills SURVIVE RenderListing's char budget, not the order they appear in — see RenderListing.

func ValidateDir

func ValidateDir(dir, source string) ([]Spec, []error)

type UsageTracker

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

func NewUsageTracker

func NewUsageTracker(path string) (*UsageTracker, error)

func (*UsageTracker) Record

func (t *UsageTracker) Record(name string, usedAt time.Time) error

func (*UsageTracker) Scores

func (t *UsageTracker) Scores(now time.Time) map[string]float64

Jump to

Keyboard shortcuts

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