skills

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package skills loads the skills a workspace offers: a SKILL.md with frontmatter and instructions, optionally scripts, from the built-in set, ~/.blitz/skills and (when trusted) the project; and the policy that caps what their scripts may do (spec_skills_013).

Index

Constants

View Source
const (
	// KindSimple is SKILL.md alone.
	KindSimple = "simple"
	// KindReferences has a references/ folder the model can read.
	KindReferences = "references"
	// KindScripts has scripts (declared, or in scripts/), and maybe
	// references too.
	KindScripts = "scripts"
	// KindMeta combines other skills (front matter skills:).
	KindMeta = "meta"
)

The four kinds of skill, told from what its folder holds rather than a field (spec_skills_013 SK-97).

View Source
const (
	ReferencesDir = "references"
	ScriptsDir    = "scripts"
)

The folders a skill's files are kept in, beside SKILL.md.

Variables

View Source
var ErrChanged = errors.New("the skill changed since it was opened")

ErrChanged means SKILL.md changed since it was read (its hash differs).

View Source
var ErrUnknownSkill = errors.New("no such skill")

ErrUnknownSkill means there's no skill folder of that name.

View Source
var PackageFiles = map[string][]string{
	"python": {"scripts/requirements.txt", "requirements.txt", "scripts/pyproject.toml", "pyproject.toml"},
	"node":   {"scripts/package.json", "package.json"},
}

PackageFiles are where a skill's scripts' packages may be listed, by kind, the first found winning: requirements.txt, then pyproject.toml ([project] dependencies) for Python, package.json for Node; in scripts/ first, then beside SKILL.md.

Functions

func Check added in v0.7.1

func Check(spec Spec, reserved func(string) bool) []string

Check returns what keeps spec from being saved: a name that isn't one, a missing description, a member that isn't a skill name or is itself. reserved says a name a built-in skill has.

func Delete added in v0.7.1

func Delete(dir, name string) error

Delete removes dir/<name>: SKILL.md and everything beside it.

func DeleteFile added in v0.7.1

func DeleteFile(dir, name, rel string) error

DeleteFile removes one of dir/<name>'s files.

func FileHash added in v0.7.1

func FileHash(data []byte) string

FileHash identifies SKILL.md's content, to tell an edit made elsewhere.

func IsPackageFile added in v0.7.1

func IsPackageFile(rel string) bool

IsPackageFile reports whether rel names one of PackageFiles.

func Render added in v0.7.1

func Render(old []byte, spec Spec) ([]byte, error)

Render is SKILL.md for spec: old's front matter (nil: none) with the fields the form edits set, or removed when empty, and the instructions as its body.

func Save added in v0.7.1

func Save(dir string, spec Spec, previous, hash string, reserved func(string) bool) (string, []string, error)

Save writes dir/<name>/SKILL.md from spec and returns its path, or the problems that keep it from being saved (nothing written). previous is the skill being edited ("" for a new one); a different name renames its folder. hash, when given, must be its SKILL.md's current FileHash.

func StorageURL

func StorageURL(uri string) (string, error)

StorageURL is where a storage_uri is fetched: https as it is, gs:// through Cloud Storage's public endpoint.

func ValidName added in v0.7.1

func ValidName(name string) bool

ValidName reports whether name may name a skill (and its folder).

func WriteFile added in v0.7.1

func WriteFile(dir, name, rel string, data []byte) error

WriteFile writes one of dir/<name>'s files (references/… or scripts/…), making its folders, through os.Root so nothing outside the skill's folder is touched.

Types

type AuthorDetails

type AuthorDetails struct {
	Name  string `yaml:"name"`
	Email string `yaml:"email,omitempty"`
	URL   string `yaml:"url,omitempty"`
}

AuthorDetails is a skill contributor.

type CompiledReference

type CompiledReference struct {
	SkillID    string   `yaml:"skill_id,omitempty"`
	SHA256Hash string   `yaml:"sha256_hash,omitempty"`
	HITLTier   HITLTier `yaml:"hitl_tier,omitempty"`
}

CompiledReference is Castor's pointer to a registered, hashed skill. Only its hash and tier are read.

type Evaluation

type Evaluation struct {
	Tier   HITLTier // approval tier its scripts run at
	Bypass bool     // Tier0BypassAll granted: the skill asked and the policy allows it
	// Network is granted: the skill asked (custom_hints.network) and is on
	// the policy's allowlist.
	Network bool
	// Env are the host environment variables the skill asked for that the
	// policy passes through; Withheld are the ones it doesn't.
	Env, Withheld []string
	Hash          string // ContentHash, "" if it couldn't be computed
	Scripts       []ScriptVerdict
	// NeedsReview means the skill's scripts, on disk, weren't reviewed and
	// trusted with this content (SK-108): each run asks first.
	NeedsReview bool
	// Blocked are reasons none of the skill's scripts may run.
	Blocked []string
}

Evaluation is what a skill may do under a host policy: for each setting, the stricter of what the skill asks for and what the policy allows.

func Evaluate

func Evaluate(s *Skill, p config.SkillPolicy) Evaluation

Evaluate applies policy p to skill s.

func (Evaluation) Runnable

func (e Evaluation) Runnable() bool

Runnable reports whether any script may run.

type ExecutionHints

type ExecutionHints struct {
	PreferredModel        string            `yaml:"preferred_model,omitempty"`
	RequiresHumanApproval bool              `yaml:"requires_human_approval,omitempty"`
	EnvironmentVariables  []string          `yaml:"environment_variables,omitempty"`
	TimeoutSeconds        int               `yaml:"timeout_seconds,omitempty"`
	CustomHints           map[string]string `yaml:"custom_hints,omitempty"`
	HITLTier              HITLTier          `yaml:"hitl_tier,omitempty"`
	AllowHITLBypass       bool              `yaml:"allow_hitl_bypass,omitempty"`
	// WritesWorkspace means the skill's scripts change the workspace's files.
	// They run in a copy of it, and what they changed is kept only once
	// approved, diff shown, as tier 3 asks (BL-SK-02).
	WritesWorkspace bool `yaml:"writes_workspace,omitempty"`
}

ExecutionHints are operational hints for running a skill.

func (*ExecutionHints) NeedsNetwork

func (h *ExecutionHints) NeedsNetwork() bool

NeedsNetwork reports whether the skill's scripts declare that they need the network. The proto has no field for it yet, so it is the custom hint network: "true" (or "required").

type HITLTier

type HITLTier int

HITLTier is a human-in-the-loop risk tier: how much approval a skill's actions need. Values match the proto enum, so the zero value is TierUnspecified (never a bypass) and higher tiers compare greater.

const (
	TierUnspecified HITLTier = iota
	Tier0BypassAll
	Tier1AutoRead
	Tier2AuditedWrite
	Tier3MandatoryApproval
)

The tiers, lowest risk first: bypass (no checks, only where the policy allows it), automatic reads, audited and checkpointed writes, and approval for everything.

func ParseHITLTier

func ParseHITLTier(s string) (HITLTier, error)

ParseHITLTier reads a tier by name: the proto enum name (HITL_POLICY_TIER_2_AUDITED_WRITE), the short form Castor stores (TIER_2_AUDITED_WRITE), or tier_2. Bare numbers are refused: the proto numbers its enum one higher than the tier, so "2" would be ambiguous.

func (HITLTier) String

func (t HITLTier) String() string

String is the tier's proto enum name, such as TIER_2_AUDITED_WRITE.

func (*HITLTier) UnmarshalYAML

func (t *HITLTier) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads a tier name (see ParseHITLTier).

type Provider

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

Provider discovers, indexes, and activates skills across embedded and external paths.

func NewProvider

func NewProvider() (*Provider, error)

NewProvider initializes the skills provider with embedded built-in skills.

func (*Provider) DiscoverExternal

func (p *Provider) DiscoverExternal(dirs []string) error

DiscoverExternal scans search directories for SKILL.md files. External skills cannot replace built-in ones; conflicts are reported in the returned (joined) error while other skills still load.

func (*Provider) External added in v0.6.5

func (p *Provider) External() int

External counts the skills found in the folders (not built in).

func (*Provider) Get

func (p *Provider) Get(name string) (*Skill, bool)

Get returns a skill by name.

func (*Provider) IsBuiltin added in v0.7.1

func (p *Provider) IsBuiltin(name string) bool

IsBuiltin reports whether name is a built-in skill's, which a skill on disk can't take.

func (*Provider) List

func (p *Provider) List() []*Skill

List returns all discovered skills sorted by name.

func (*Provider) Refresh added in v0.6.5

func (p *Provider) Refresh() bool

Refresh searches the folders again when what they hold changed since it last did, so skills installed, edited or removed meanwhile come and go without a restart, and reports whether it did. Their problems were reported when the workspace opened; doctor reports a new one.

func (*Provider) Reload added in v0.6.5

func (p *Provider) Reload() error

Reload searches the folders again whether or not they look changed (/reload), and returns what couldn't be loaded.

func (*Provider) Search

func (p *Provider) Search(query string) []*Skill

Search filters skills matching query in name, description, or tags.

type ResourceInterpretation

type ResourceInterpretation struct {
	InterpretedText string   `yaml:"interpreted_text,omitempty"`
	Summary         string   `yaml:"summary,omitempty"`
	KeyEntities     []string `yaml:"key_entities,omitempty"`
}

ResourceInterpretation is text a resource was turned into.

type ResourceRequirement

type ResourceRequirement struct {
	ID             string                  `yaml:"id,omitempty"`
	Name           string                  `yaml:"name,omitempty"`
	Description    string                  `yaml:"description,omitempty"`
	Category       string                  `yaml:"category,omitempty"` // RESOURCE_CATEGORY_DOCUMENT_TEXT, or document_text
	MimeType       string                  `yaml:"mime_type,omitempty"`
	Storage        *ResourceStorage        `yaml:"storage,omitempty"`
	InlineContent  string                  `yaml:"inline_content,omitempty"`
	Interpretation *ResourceInterpretation `yaml:"interpretation,omitempty"`
	// AutoInjectContext means the interpretation goes with the instructions.
	AutoInjectContext bool `yaml:"auto_inject_context,omitempty"`
}

ResourceRequirement is Castor's context asset (castor.skills.v1).

func (ResourceRequirement) CategoryName

func (r ResourceRequirement) CategoryName() string

CategoryName is a resource category's short form ("document_text").

type ResourceStorage

type ResourceStorage struct {
	GCSURI             string `yaml:"gcs_uri,omitempty"`
	PublicURL          string `yaml:"public_url,omitempty"`
	GeminiFilesAPIName string `yaml:"gemini_files_api_name,omitempty"`
	GeminiFilesAPIURI  string `yaml:"gemini_files_api_uri,omitempty"`
	SizeBytes          int64  `yaml:"size_bytes,omitempty"`
	MimeType           string `yaml:"mime_type,omitempty"`
	SHA256Hash         string `yaml:"sha256_hash,omitempty"`
}

ResourceStorage is where a resource lives.

type ScriptDefinition

type ScriptDefinition struct {
	Name                 string            `yaml:"name"`
	Description          string            `yaml:"description,omitempty"`
	Language             ScriptLanguage    `yaml:"language,omitempty"`
	InlineCode           string            `yaml:"inline_code,omitempty"`
	StorageURI           string            `yaml:"storage_uri,omitempty"`
	RelativePath         string            `yaml:"relative_path,omitempty"`
	EntryPoint           string            `yaml:"entry_point,omitempty"`
	Dependencies         []string          `yaml:"dependencies,omitempty"`
	TimeoutSeconds       int               `yaml:"timeout_seconds,omitempty"`
	EnvironmentVariables map[string]string `yaml:"environment_variables,omitempty"`
	// StorageSHA256 pins a storage_uri script's content: the hex SHA-256
	// it must have (Blitz's field; Castor's proto has none).
	StorageSHA256 string `yaml:"storage_sha256,omitempty"`
	// RequiresPython is the Python a script needs (">=3.11"); without it,
	// the script's PEP 723 metadata may say (BL-SK-03).
	RequiresPython string `yaml:"requires_python,omitempty"`
	// Found means it wasn't declared but found in scripts/ (SK-98).
	Found bool `yaml:"-"`
}

ScriptDefinition is a helper script shipped with (or referenced by) a skill. Exactly one of InlineCode, StorageURI and RelativePath is its source.

type ScriptLanguage

type ScriptLanguage string

ScriptLanguage is a script's runtime.

const (
	LanguageUnspecified ScriptLanguage = ""
	LanguagePython      ScriptLanguage = "python"
	LanguageTypeScript  ScriptLanguage = "typescript"
	// LanguageShell is a POSIX shell script (/bin/sh; macOS and Linux) and
	// LanguageCmd a Windows batch script (cmd.exe): Blitz's, not Castor's
	// (spec_skills_013 SK-105).
	LanguageShell ScriptLanguage = "shell"
	LanguageCmd   ScriptLanguage = "cmd"
	// LanguageJavaScript runs with node, as TypeScript does, and
	// LanguagePowerShell with pwsh (or Windows PowerShell): Blitz's too
	// (SK-106).
	LanguageJavaScript ScriptLanguage = "javascript"
	LanguagePowerShell ScriptLanguage = "powershell"
)

The languages a skill's scripts can be written in; a script must name one (unspecified is a problem the skill's validation reports).

func ScriptLanguageOf added in v0.7.1

func ScriptLanguageOf(name string) ScriptLanguage

ScriptLanguageOf is the language of a script file, by its extension (.py, .ts, .js, .mjs, .sh, .cmd, .bat, .ps1); unspecified for anything else.

func (ScriptLanguage) Node added in v0.7.1

func (l ScriptLanguage) Node() bool

Node reports whether the language's scripts run with node (TypeScript, JavaScript), with npm packages.

func (ScriptLanguage) Platform added in v0.7.1

func (l ScriptLanguage) Platform() string

Platform is the operating system a language's scripts run on ("" for any): shell scripts need a POSIX shell, cmd scripts Windows.

func (*ScriptLanguage) UnmarshalYAML

func (l *ScriptLanguage) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads python / typescript, or the proto enum names.

type ScriptVerdict

type ScriptVerdict struct {
	Name           string
	Allowed        bool
	Reasons        []string // why it may not run
	TimeoutSeconds int      // capped by the policy
	Dependencies   []string
}

ScriptVerdict is whether one script may run, and with what limits.

type Skill

type Skill struct {
	SkillMetadata
	Content   string   `json:"content"`
	Path      string   `json:"path"`
	Resources []string `json:"resources"`
	// References are the files under references/, as references/<path>
	// (also in Resources).
	References []string `json:"references,omitempty"`
	// PackageFiles are the package files its folder has (requirements.txt,
	// pyproject.toml, package.json; SK-107), as paths in it.
	PackageFiles []string `json:"package_files,omitempty"`
	// Problems are definition errors (see SkillMetadata.Validate).
	Problems []string `json:"problems,omitempty"`
	// contains filtered or unexported fields
}

Skill represents an Agent Skill specification.

func Builtins added in v0.7.1

func Builtins() ([]*Skill, error)

Builtins are the skills Blitz ships with, by name: what every workspace has before it finds any of its own (Settings › Skills lists them).

func LoadFolder added in v0.7.1

func LoadFolder(dir string) (*Skill, error)

LoadFolder reads the skill in folder dir (its SKILL.md and what's beside it), as discovery would.

func ParseSkillMD

func ParseSkillMD(content []byte, path string) (*Skill, error)

ParseSkillMD parses a SKILL.md document with YAML frontmatter.

func (*Skill) ContentHash

func (s *Skill) ContentHash() (string, error)

ContentHash is the SHA-256 of every regular file in the skill's directory (SKILL.md, scripts, resources), in path order, each as its relative path, its size and its content. It identifies exactly what was reviewed, so a config can pin a skill (skills.policy.trusted_hashes). Symbolic links are skipped. The format is "sha256:<hex>".

func (*Skill) CopyTo

func (s *Skill) CopyTo(dir string) error

CopyTo writes the skill's files into dir (for built-in skills, whose files are embedded). Symbolic links are skipped.

func (*Skill) HostDir

func (s *Skill) HostDir() string

HostDir is the skill's directory on disk, or "" for built-in skills.

func (*Skill) Kind added in v0.7.1

func (s *Skill) Kind() string

Kind is which of the four kinds the skill is (SK-97): meta when it names other skills, else scripts, references or simple by what its folder holds.

func (*Skill) Matches

func (s *Skill) Matches(query string) bool

Matches returns true if the query matches the skill's name, description, or tags.

func (*Skill) OfferedTo added in v0.7.1

func (s *Skill) OfferedTo(agent string) bool

OfferedTo reports whether the skill is offered to the named agent (front matter agents:; none means every agent).

func (*Skill) ReadScript

func (s *Skill) ReadScript(rel string) ([]byte, error)

ReadScript returns a script's source shipped in the skill (relative_path): from its directory, or from the embedded files of a built-in skill.

func (*Skill) ScriptPath

func (s *Skill) ScriptPath(rel string) (string, error)

ScriptPath returns the host path of a script shipped in the skill's directory (relative_path), checked through os.Root so neither ".." nor a symbolic link can lead outside the directory. Built-in skills have no host directory; use CopyTo.

type SkillMetadata

type SkillMetadata struct {
	// Agent Skills spec.
	Name          string            `yaml:"name"`
	Description   string            `yaml:"description"`
	License       string            `yaml:"license,omitempty"`
	Compatibility string            `yaml:"compatibility,omitempty"`
	AllowedTools  string            `yaml:"allowed-tools,omitempty"`
	Metadata      map[string]string `yaml:"metadata,omitempty"`

	// Castor (castor.skills.v1.SkillDefinition).
	Tags               []string           `yaml:"tags"`
	Version            string             `yaml:"version,omitempty"`
	Author             string             `yaml:"author,omitempty"`
	Authors            []AuthorDetails    `yaml:"authors,omitempty"`
	AllowedToolsLegacy string             `yaml:"allowed_tools,omitempty"`
	ToolRequirements   []ToolRequirement  `yaml:"tool_requirements,omitempty"`
	Category           string             `yaml:"category,omitempty"`
	TriggerPhrases     []string           `yaml:"trigger_phrases,omitempty"`
	ExecutionHints     *ExecutionHints    `yaml:"execution_hints,omitempty"`
	CompiledReference  *CompiledReference `yaml:"compiled_reference,omitempty"`
	Scripts            []ScriptDefinition `yaml:"scripts,omitempty"`
	// ResourceRequirements are Castor's resources: context assets the
	// skill uses, listed by activate_skill.
	ResourceRequirements []ResourceRequirement `yaml:"resources,omitempty"`
	SkillID              string                `yaml:"skill_id,omitempty"`
	URI                  string                `yaml:"uri,omitempty"`
	SourceURI            string                `yaml:"source_uri,omitempty"`

	// Agents are the agents the skill is offered to (none: every one);
	// Members the skills a meta skill combines (spec_skills_013 SK-99).
	Agents  []string `yaml:"agents,omitempty"`
	Members []string `yaml:"skills,omitempty"`
}

SkillMetadata defines metadata stored in SKILL.md frontmatter: the Agent Skills spec fields, plus Castor's skill definition fields (see definition.go). Unknown keys are ignored, so skills written for other tools still load.

func (*SkillMetadata) AllowedToolsList

func (m *SkillMetadata) AllowedToolsList() []string

AllowedToolsList is the spec's allowed-tools (or Castor's legacy allowed_tools), split on spaces and commas.

func (*SkillMetadata) DeclaredTier

func (m *SkillMetadata) DeclaredTier() HITLTier

DeclaredTier is the tier the skill asks for: execution_hints.hitl_tier, else the compiled reference's, and at least tier 3 when it says it requires human approval.

func (*SkillMetadata) Validate

func (m *SkillMetadata) Validate() []string

Validate reports problems with the skill's definition. A skill with problems still loads (its instructions are useful), but the scripts involved are not run.

type Spec added in v0.7.1

type Spec struct {
	Name         string
	Description  string
	Tools        string
	Agents       []string
	Members      []string
	Instructions string
}

Spec is what the form edits: the skill's name (its folder's), what it's for, the tools it may use (allowed-tools, as written), the agents it's offered to, the skills it combines and its instructions.

type ToolRequirement

type ToolRequirement struct {
	Name        string   `yaml:"name"`
	Scopes      []string `yaml:"scopes,omitempty"`
	Description string   `yaml:"description,omitempty"`
}

ToolRequirement is a tool a skill needs, with the scopes it needs it for (e.g. Bash with ["git:*"]).

Directories

Path Synopsis
Package builtin holds the skills Blitz ships with (a SKILL.md each), embedded in the binary.
Package builtin holds the skills Blitz ships with (a SKILL.md each), embedded in the binary.

Jump to

Keyboard shortcuts

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