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_013_skills).
Index ¶
- Constants
- Variables
- func Check(spec Spec, reserved func(string) bool) []string
- func CheckScenario(sc Scenario) []string
- func CleanTriggers(phrases []string) []string
- func Delete(dir, name string) error
- func DeleteFile(dir, name, rel string) error
- func DeleteScenario(dir, skill, name string) error
- func FileHash(data []byte) string
- func IsPackageFile(rel string) bool
- func Render(old []byte, spec Spec) ([]byte, error)
- func Save(dir string, spec Spec, previous, hash string, reserved func(string) bool) (string, []string, error)
- func SaveScenario(dir, skill string, sc Scenario, previous string) (string, []string, error)
- func StorageURL(uri string) (string, error)
- func TriggerHint(phrases []string) string
- func TriggerMatches(request, phrase string) bool
- func ValidName(name string) bool
- func WriteFile(dir, name, rel string, data []byte) error
- type AuthorDetails
- type CompiledReference
- type Evaluation
- type ExecutionHints
- type HITLTier
- type Provider
- func (p *Provider) DiscoverExternal(dirs []string) error
- func (p *Provider) External() int
- func (p *Provider) Get(name string) (*Skill, bool)
- func (p *Provider) GetFor(agent, name string) (*Skill, bool)
- func (p *Provider) IsBuiltin(name string) bool
- func (p *Provider) List() []*Skill
- func (p *Provider) ListFor(agent string) []*Skill
- func (p *Provider) Lock(dirs ...string)
- func (p *Provider) Refresh() bool
- func (p *Provider) Reload() error
- func (p *Provider) Search(query string) []*Skill
- func (p *Provider) SetVersions(versions func(agent string) map[string]string)
- func (p *Provider) SwitchOff(names []string)
- type ResourceInterpretation
- type ResourceRequirement
- type ResourceStorage
- type Scenario
- type ScriptDefinition
- type ScriptLanguage
- type ScriptVerdict
- type Skill
- func (s *Skill) ContentHash() (string, error)
- func (s *Skill) CopyTo(dir string) error
- func (s *Skill) HostDir() string
- func (s *Skill) Kind() string
- func (s *Skill) Matches(query string) bool
- func (s *Skill) OfferedTo(agent string) bool
- func (s *Skill) ReadScript(rel string) ([]byte, error)
- func (s *Skill) ScriptPath(rel string) (string, error)
- type SkillMetadata
- type Spec
- type ToolRequirement
Constants ¶
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_013_skills SK-97).
const ( ReferencesDir = "references" ScriptsDir = "scripts" // ScenariosDir holds Castor's scenarios: the skill's behaviour tests // (scenarios.go). ScenariosDir = "scenarios" )
The folders a skill's files are kept in, beside SKILL.md.
const ( MaxTriggers = 20 MaxTriggerLength = 200 )
Limits on trigger phrases: how many, and how long each.
const DefaultScenarioThreshold = 0.8
DefaultScenarioThreshold is a scenario's threshold when it gives none.
Variables ¶
var ErrBadPath = errors.New("not one of the skill's files")
ErrBadPath means a path that isn't one of a skill's own files: outside its folder, or not where its files go.
var ErrChanged = errors.New("the skill changed since it was opened")
ErrChanged means SKILL.md changed since it was read (its hash differs).
var ErrUnknownScenario = errors.New("no such scenario")
ErrUnknownScenario is a scenario the skill doesn't have.
var ErrUnknownSkill = errors.New("no such skill")
ErrUnknownSkill means there's no skill folder of that name.
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
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 CheckScenario ¶ added in v0.8.0
CheckScenario returns what keeps sc from being saved or run.
func CleanTriggers ¶ added in v0.8.0
CleanTriggers trims each phrase and leaves out blank ones and repeats.
func DeleteFile ¶ added in v0.7.1
DeleteFile removes one of dir/<name>'s files.
func DeleteScenario ¶ added in v0.8.0
DeleteScenario removes dir/<skill>/scenarios/<name>.md.
func FileHash ¶ added in v0.7.1
FileHash identifies SKILL.md's content, to tell an edit made elsewhere.
func IsPackageFile ¶ added in v0.7.1
IsPackageFile reports whether rel names one of PackageFiles.
func Render ¶ added in v0.7.1
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 SaveScenario ¶ added in v0.8.0
SaveScenario writes dir/<skill>/scenarios/<sc.Name>.md, keeping the front matter's other fields when it replaces previous ("" for a new one; a different name renames it), and returns its path, or the problems that keep it from being saved (nothing written).
func StorageURL ¶
StorageURL is where a storage_uri is fetched: https as it is, gs:// through Cloud Storage's public endpoint.
func TriggerHint ¶ added in v0.8.0
TriggerHint is how the skills' listing gives a skill's trigger phrases (SK-110): " For requests like: "a"; "b".", or "" without any.
func TriggerMatches ¶ added in v0.8.0
TriggerMatches reports whether a request is near a trigger phrase (SK-110): one holds the other, or it has most of the phrase's words (two thirds of those that aren't stop words, however short: "pdf" counts, "the" doesn't; all of them when every one is a stop word), a word matching one that starts the same (plurals, other endings). Phrases are examples, so no two people need write them alike.
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 ¶
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.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider discovers, indexes, and activates skills across embedded and external paths.
func NewProvider ¶
NewProvider initializes the skills provider with embedded built-in skills.
func (*Provider) DiscoverExternal ¶
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
External counts the skills found in the folders (not built in).
func (*Provider) GetFor ¶ added in v1.1.0
GetFor is the skill name as agent runs it: its own version when the organization published it with one (EN-82), else the provider's.
func (*Provider) IsBuiltin ¶ added in v0.7.1
IsBuiltin reports whether name is a built-in skill's, which a skill on disk can't take.
func (*Provider) ListFor ¶ added in v1.1.0
ListFor is every skill as agent runs it: the provider's, with each its own version replaces.
func (*Provider) Lock ¶ added in v0.9.1
Lock marks dirs as the organization's locked skill folders (spec_053 EN-81): a skill found in one wins over a skill of its name in any other folder, whichever is searched first, and the clash is reported. An empty dir is ignored. Call it before DiscoverExternal.
func (*Provider) Refresh ¶ added in v0.6.5
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
Reload searches the folders again whether or not they look changed (/reload), and returns what couldn't be loaded.
func (*Provider) SetVersions ¶ added in v1.1.0
SetVersions gives the provider each agent's own versions of its skills (spec_053 EN-82): versions(agent) is, by skill name, the folder of the version that agent was published with, or nil for none. Called once, before the provider's first use by an agent.
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 Scenario ¶ added in v0.8.0
type Scenario struct {
// Name is its file's, without .md.
Name string
Description string
Prompt string
// Executes says the skills should be used for the prompt; false, that
// the skill shouldn't be.
Executes bool
// ExpectedSkills must all be used when Executes (none: the skill).
ExpectedSkills []string
Threshold float64
// Outcome is the answer expected, scored by meaning.
Outcome string
// Path is its file; Problem why it can't be read or run.
Path string
Problem string
}
Scenario is one of a skill's scenarios.
func LoadScenarios ¶ added in v0.8.0
LoadScenarios reads dir's *.md, by name; one that can't be read or run is listed with its problem.
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_013_skills 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
Builtins are the skills Blitz ships with, by name: what every workspace has before it finds any of its own (Settings › Resources › Skills lists them).
func LoadFolder ¶ added in v0.7.1
LoadFolder reads the skill in folder dir (its SKILL.md and what's beside it), as discovery would.
func ParseSkillMD ¶
ParseSkillMD parses a SKILL.md document with YAML frontmatter.
func (*Skill) ContentHash ¶
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 ¶
CopyTo writes the skill's files into dir (for built-in skills, whose files are embedded). Symbolic links are skipped.
func (*Skill) Kind ¶ added in v0.7.1
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 ¶
Matches returns true if the query matches the skill's name, description, or tags.
func (*Skill) OfferedTo ¶ added in v0.7.1
OfferedTo reports whether the skill is offered to the named agent (front matter agents:; none means every agent).
func (*Skill) ReadScript ¶
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 ¶
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_013_skills 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, except where a typo would lower protection silently (see unknownKeys).
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
// Triggers are Castor's trigger_phrases: requests the skill is for,
// examples the model matches by meaning, not wording (SK-110).
Triggers []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:*"]).