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
- Variables
- func Check(spec Spec, reserved func(string) bool) []string
- func Delete(dir, name string) error
- func DeleteFile(dir, name, rel 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 StorageURL(uri string) (string, error)
- 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) IsBuiltin(name string) bool
- func (p *Provider) List() []*Skill
- func (p *Provider) Refresh() bool
- func (p *Provider) Reload() error
- func (p *Provider) Search(query string) []*Skill
- type ResourceInterpretation
- type ResourceRequirement
- type ResourceStorage
- 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_skills_013 SK-97).
const ( ReferencesDir = "references" ScriptsDir = "scripts" )
The folders a skill's files are kept in, beside SKILL.md.
Variables ¶
var ErrChanged = errors.New("the skill changed since it was opened")
ErrChanged means SKILL.md changed since it was read (its hash differs).
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 DeleteFile ¶ added in v0.7.1
DeleteFile removes one of dir/<name>'s files.
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 StorageURL ¶
StorageURL is where a storage_uri is fetched: https as it is, gs:// through Cloud Storage's public endpoint.
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) 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) 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.
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
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
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_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:*"]).