skills

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: GPL-3.0 Imports: 24 Imported by: 0 modules, 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 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

View Source
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.

View Source
const DefaultLockfile = "skills.lock"

DefaultLockfile is the lockfile's name in the project directory.

View Source
const LockfileVersion = 1

LockfileVersion is the version of the lockfile format this package writes.

View Source
const ManifestName = "SKILL.md"

ManifestName is the file that makes a directory a skill.

Variables

View Source
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.

View Source
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

func Badge(l Label) string

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

func CapabilityTitle(id string) string

CapabilityTitle is the one-line title of a capability.

func Imperative

func Imperative(sentence string) bool

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

func LabelMarkdown(key string, l Label) string

LabelMarkdown renders a skill's label: its badge, and a table of what it can do with where each capability was seen.

func Markdown

func Markdown(reports []Report, lockfile string) string

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

func MarkdownDiff(d []DiffLine) string

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

func MerkleRoot(files []File) string

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

func Reveal(s string) string

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

func RevealLine(s string) string

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.

func ProseDiff

func ProseDiff(before, after string) []DiffLine

ProseDiff compares two versions of a SKILL.md sentence by sentence, so that one new sentence in a long paragraph shows as one new sentence. Added sentences that give the model an order are marked, and so is every rule an added unit trips.

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.

func (Evidence) Where

func (e Evidence) Where() string

Where is file:line.

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.

func Scan

func Scan(s *Skill) []Finding

Scan runs every rule over a skill.

func (Finding) Key

func (f Finding) Key() string

Key identifies a finding for acceptance. It leaves the line out, so a finding a human accepted stays accepted when a line is added above it.

func (Finding) Where

func (f Finding) Where() string

Where is file:line.

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.

func Derive

func Derive(s *Skill) Label

Derive works out a skill's label.

func (Label) Has

func (l Label) Has(id string) bool

Has reports whether the label lists a capability.

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

func LoadLockfile(path string) (*Lockfile, error)

LoadLockfile reads a lockfile. A missing file is an empty lockfile; Exists tells the two apart.

func (*Lockfile) Approve

func (l *Lockfile) Approve(r Report, by string, now time.Time)

Approve records a skill as it is now; a removed skill is forgotten.

func (*Lockfile) Check

func (l *Lockfile) Check(skills []*Skill) []Report

Check compares the skills on disk with the lockfile.

func (*Lockfile) Exists

func (l *Lockfile) Exists() bool

Exists reports whether the lockfile is on disk.

func (*Lockfile) Path

func (l *Lockfile) Path() string

Path is where the lockfile lives.

func (*Lockfile) Save

func (l *Lockfile) Save() error

Save writes the lockfile atomically. Characters that render as nothing are written as \u escapes, so a hidden instruction stays visible in the lockfile's own diff.

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.

func (Options) Roots

func (o Options) Roots() ([]Root, error)

Roots lists the directories to look in, whether they exist or not.

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.

func (Report) Clean

func (r Report) Clean() bool

Clean reports whether the skill needs no one's attention.

func (Report) Match

func (r Report) Match(name string) bool

Match reports whether a name given on the command line means this skill: its key, or the last element of its key. The name in the front matter is not matched: a skill chooses that itself, and could choose another's.

type Root

type Root struct {
	Path string
	// Scope is project, user, plugin or path.
	Scope string
}

Root is one directory skills are looked for in.

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.

func Rules

func Rules() []Rule

Rules lists every rule, in the order the documentation shows them.

type Severity

type Severity string

Severity says how much a finding should worry a reviewer.

const (
	High   Severity = "high"
	Medium Severity = "medium"
	Low    Severity = "low"
)

Severities, from the most to the least worrying.

func ParseSeverity

func ParseSeverity(s string) (Severity, error)

ParseSeverity reads a severity, or "none".

func (Severity) Rank

func (s Severity) Rank() int

Rank orders severities: high is 3, low is 1, anything else 0.

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

func Discover(o Options) ([]*Skill, error)

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.

func Load

func Load(dir, key string) (*Skill, error)

Load reads a skill directory: every file is hashed, the text ones are kept for the scan. A symlink inside the skill is pinned by where it points and, when that is a file, by what the file says; it is never walked into. Named pipes and devices are recorded, never opened.

func (*Skill) Manifest

func (s *Skill) Manifest() string

Manifest is the text of SKILL.md.

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"
)

Jump to

Keyboard shortcuts

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