Documentation
¶
Overview ¶
Package skills pins Agent Skills the way package-lock.json pins packages.
A skill is a directory with a SKILL.md in it — instructions in plain language, and often scripts next to them — that a coding agent loads into its context and follows. That makes a skill a dependency like any other, with one difference: its payload is prose, read by a model. A skill that was harmless when it was installed can be changed later, and one that ships a hidden instruction from the start looks, to a person, exactly like one that does not.
This package hashes every file of a skill into a Merkle root, derives a label of what the skill can do (reach the network, run a shell, read secrets, ...), runs a set of deterministic rules for the tricks poisoned skills use, and keeps all of it in a lockfile. A change to any file, a new capability or a new finding is drift until a human approves it.
Index ¶
- Constants
- Variables
- func Badge(l Label) string
- func CapabilityTitle(id string) string
- func Imperative(sentence string) bool
- func LabelMarkdown(key string, l Label) string
- func Markdown(reports []Report, lockfile string) string
- func MarkdownDiff(d []DiffLine) string
- func MerkleRoot(files []File) string
- func Reveal(s string) string
- func RevealLine(s string) string
- func SortCapabilities(ids []string)
- type Capability
- type DiffLine
- type Entry
- type Evidence
- type File
- type FileChange
- type Finding
- type Label
- type Lockfile
- type Options
- type Report
- type Root
- type Rule
- type Severity
- type Skill
- type Status
Constants ¶
const ( KindFile = "file" KindSymlink = "symlink" KindSpecial = "special" // KindRepository is a git repository at the root of a skill: its // presence is pinned, its content is not. KindRepository = "repository" )
File kinds.
const DefaultLockfile = "skills.lock"
DefaultLockfile is the lockfile's name in the project directory.
const LockfileVersion = 1
LockfileVersion is the version of the lockfile format this package writes.
const ManifestName = "SKILL.md"
ManifestName is the file that makes a directory a skill.
Variables ¶
var ProjectRoots = []string{".claude/skills", ".agents/skills", ".codex/skills"}
ProjectRoots are where agents look for a project's skills, relative to the project directory: Claude Code in .claude/skills, Codex and the other agents that follow the Agent Skills layout in .agents/skills, and older Codex releases in .codex/skills.
var UserRoots = []string{".claude/skills", ".agents/skills", ".codex/skills"}
UserRoots are where agents look for a user's own skills, relative to the home directory.
Functions ¶
func Badge ¶
Badge is a shields.io badge of a skill's label, as Markdown, for the skill's README. Building the link sends nothing anywhere; showing the image asks shields.io to draw it.
func CapabilityTitle ¶
CapabilityTitle is the one-line title of a capability.
func Imperative ¶
Imperative reports whether a sentence gives the model an order: it starts with a verb in the imperative, or says "you must", "make sure" and the like.
func LabelMarkdown ¶
LabelMarkdown renders a skill's label: its badge, and a table of what it can do with where each capability was seen.
func Markdown ¶
Markdown renders the reports for a pull request comment or a CI job summary: a table of every skill, and for each one that needs a human, what changed and what its instructions now say. Everything taken from a skill is revealed (hidden characters spelled out) and escaped, so a skill cannot break out of the code block or the table it is shown in.
func MarkdownDiff ¶
MarkdownDiff renders a prose diff as a diff code block. Added sentences that give an order are marked [imperative], and every rule an added unit trips is named after it.
func MerkleRoot ¶
MerkleRoot is the root of a Merkle tree over a skill's files, in the shape of RFC 6962 (Certificate Transparency): a leaf is SHA-256(0x00 || leaf data), an inner node is SHA-256(0x01 || left || right), and a tree of n leaves splits at the largest power of two below n. The prefixes keep a leaf from ever being passed off as a node.
A leaf's data is the file's path, its kind and the hash of its content, separated by NUL bytes, so renaming a file changes the root as surely as editing it does. files must be sorted by path.
func Reveal ¶
Reveal spells out what a text hides, as pinning.Reveal does — tag text in «hidden: …», invisible and reordering characters by code point — and variation selectors too.
func RevealLine ¶
RevealLine is Reveal for text that has to stay on one line — a path, a key, an excerpt in a terminal: line breaks are spelled out too.
func SortCapabilities ¶
func SortCapabilities(ids []string)
SortCapabilities puts capability IDs in label order.
Types ¶
type Capability ¶
type Capability struct {
ID string `json:"id"`
Title string `json:"title"`
// Why says what counts, and what does not.
Why string `json:"why"`
// contains filtered or unexported fields
}
Capability is one class of thing a skill can make the agent do.
func Capabilities ¶
func Capabilities() []Capability
Capabilities lists every capability class, in the order the label shows them.
type DiffLine ¶
type DiffLine struct {
// Op is "=" for context, "+" for added, "-" for removed, or "…" for
// unchanged units left out.
Op string `json:"op"`
// Line is where the unit starts: in the approved SKILL.md for a removed
// unit, in the current one otherwise.
Line int `json:"line,omitempty"`
Kind string `json:"kind,omitempty"`
Text string `json:"text,omitempty"`
// Imperative marks an added sentence that tells the model to do
// something.
Imperative bool `json:"imperative,omitempty"`
// Rules are the rules an added unit trips on its own.
Rules []string `json:"rules,omitempty"`
}
DiffLine is one unit of a prose diff: a sentence of prose, a line of code or front matter.
type Entry ¶
type Entry struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
// Root is the Merkle root over every file.
Root string `json:"root"`
// Files maps each file to the hash of its content, "-> target" for a
// symlink, or "special" for a pipe or device.
Files map[string]string `json:"files"`
// Label is the capabilities the skill had when it was approved.
Label []string `json:"label"`
Hosts []string `json:"hosts,omitempty"`
// Accepted are the findings a human looked at and approved.
Accepted []string `json:"accepted_findings,omitempty"`
// Instructions is SKILL.md as it was approved, for the prose diff.
Instructions string `json:"instructions"`
ApprovedAt time.Time `json:"approved_at"`
ApprovedBy string `json:"approved_by,omitempty"`
}
Entry is one skill as it was approved.
type Evidence ¶
type Evidence struct {
Capability string `json:"capability"`
File string `json:"file"`
Line int `json:"line,omitempty"`
Excerpt string `json:"excerpt"`
}
Evidence is where a capability was seen.
type File ¶
type File struct {
// Path is relative to the skill directory, with forward slashes.
Path string `json:"path"`
Kind string `json:"kind"`
// Hash is the SHA-256 of the content, with CRLF line endings of a text
// file read as LF; of a symlink, its target.
Hash string `json:"hash"`
Size int64 `json:"size"`
// Target is where a symlink points.
Target string `json:"target,omitempty"`
// Binary is set for content that is not UTF-8 text.
Binary bool `json:"binary,omitempty"`
// Truncated is set when only the first part of the file was scanned.
Truncated bool `json:"truncated,omitempty"`
// Malformed is set for a text file with NUL bytes or invalid UTF-8.
Malformed bool `json:"malformed,omitempty"`
// contains filtered or unexported fields
}
File is one file of a skill, as it is on disk.
type FileChange ¶
type FileChange struct {
Path string `json:"path"`
// Change is added, removed or modified.
Change string `json:"change"`
}
FileChange is one file that differs from the lockfile.
type Finding ¶
type Finding struct {
Rule string `json:"rule"`
Severity Severity `json:"severity"`
// File is relative to the skill directory.
File string `json:"file"`
Line int `json:"line,omitempty"`
// Detail says what was found, in words.
Detail string `json:"detail"`
// Excerpt is the text in question; for hidden characters, what they
// spell out.
Excerpt string `json:"excerpt,omitempty"`
}
Finding is one thing a rule found in a skill.
type Label ¶
type Label struct {
// Capabilities are the IDs, sorted.
Capabilities []string `json:"capabilities"`
// Hosts are the hosts of every URL in the skill, sorted.
Hosts []string `json:"hosts,omitempty"`
Evidence []Evidence `json:"evidence,omitempty"`
}
Label is what a skill can do, derived from what is in it.
type Lockfile ¶
type Lockfile struct {
Version int `json:"version"`
// Paths and User are where the skills were looked for, so that a check
// on another machine looks in the same places.
Paths []string `json:"paths,omitempty"`
User bool `json:"user,omitempty"`
Skills map[string]*Entry `json:"skills"`
// contains filtered or unexported fields
}
Lockfile is the record of every skill a human has approved.
func LoadLockfile ¶
LoadLockfile reads a lockfile. A missing file is an empty lockfile; Exists tells the two apart.
type Options ¶
type Options struct {
// Dir is the project directory. Skill keys are relative to it.
Dir string
// Paths are more directories to look in, relative to Dir or absolute,
// and may be globs. A path may name a skills directory or a single
// skill.
Paths []string
// User also looks in the home directory, plugins included.
User bool
// Exclude is a file never read as part of a skill: the lockfile, when
// a skill directory holds it.
Exclude string
// PathsOnly looks in Paths alone, not in the project's skill
// directories.
PathsOnly bool
// Home overrides the home directory, for tests.
Home string
}
Options says where to look for skills.
type Report ¶
type Report struct {
Key string `json:"key"`
Name string `json:"name"`
Status Status `json:"status"`
Root string `json:"root,omitempty"`
// LockedRoot is the approved root, when there is one.
LockedRoot string `json:"locked_root,omitempty"`
// Label is the skill's capabilities now.
Label []string `json:"label"`
// Gained and Lost compare the label with the approved one.
Gained []string `json:"gained,omitempty"`
Lost []string `json:"lost,omitempty"`
NewHosts []string `json:"new_hosts,omitempty"`
// Findings is everything the rules find in the skill now; Unaccepted
// is the part of it that was not approved with the skill.
Findings []Finding `json:"findings,omitempty"`
Unaccepted []Finding `json:"unaccepted,omitempty"`
Files []FileChange `json:"files,omitempty"`
Skill *Skill `json:"-"`
Entry *Entry `json:"-"`
Labelled Label `json:"-"`
}
Report is the verdict on one skill.
type Rule ¶
type Rule struct {
ID string `json:"id"`
Severity Severity `json:"severity"`
// Title is what a finding says.
Title string `json:"title"`
// Why explains what the rule is for, and what it is not.
Why string `json:"why"`
// contains filtered or unexported fields
}
Rule is one deterministic check.
type Severity ¶
type Severity string
Severity says how much a finding should worry a reviewer.
Severities, from the most to the least worrying.
func ParseSeverity ¶
ParseSeverity reads a severity, or "none".
type Skill ¶
type Skill struct {
// Key identifies the skill in the lockfile: its directory relative to
// the project, or under ~ for a skill in the home directory.
Key string `json:"key"`
// Dir is where it is on disk.
Dir string `json:"dir"`
// Name is the name from the front matter, or the directory's.
Name string `json:"name"`
Description string `json:"description,omitempty"`
// Link is where the skill directory points, when it is a symlink.
Link string `json:"link,omitempty"`
Files []File `json:"files"`
// Root is the Merkle root over every file.
Root string `json:"root"`
// Front is the parsed front matter of SKILL.md; FrontErr says why it
// could not be parsed.
Front map[string]any `json:"-"`
FrontErr string `json:"-"`
}
Skill is one skill directory, read from disk.
func Discover ¶
Discover finds and loads every skill. A directory without a SKILL.md is not a skill and is passed over; a root that does not exist is fine.
type Status ¶
type Status string
Status is how a skill on disk relates to the lockfile.
const ( // StatusLocked means the skill is exactly what was approved. StatusLocked Status = "locked" // StatusNew means the skill is not in the lockfile. StatusNew Status = "new" // StatusChanged means a file of the skill changed since it was approved. StatusChanged Status = "changed" // StatusRemoved means the skill is in the lockfile but gone from disk. StatusRemoved Status = "removed" // StatusRescanned means the files are unchanged, but this agentgate // sees capabilities or findings the lockfile does not record - after an // upgrade that brought new rules. StatusRescanned Status = "rescanned" )