skills

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 1 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 parses Claude Code's skills listing — the prose block that declares which skills a request carries.

It exists as a shared package for one reason: two places need the SAME parse and they must not drift. The dashboard reads the listing to price each entry (dash/toolinventory.go); the declaration filter cuts entries out of it (apply/toolfilter.go). A filter that disagreed with the inventory about where an entry ENDS would leave an orphaned description line behind in a real request — prose with no heading, attached to the wrong skill — while the page that authorised the removal reported a clean cut. This repo has shipped that class of bug before (two cost columns priced from different maps, 31.6% apart), so the rule lives once.

The listing is not JSON and cannot be treated as though it were. It is prose inside a `<system-reminder>` in a role:"system" MESSAGE — measured on real traffic: messages[1], a plain string, 6,867 bytes — so everything here is line-oriented and every function fails closed: a line that does not clearly parse as an entry is not one.

Index

Constants

View Source
const Header = "The following skills are available for use with the Skill tool:"

Header anchors the listing, and the anchor is load-bearing rather than cosmetic: the agent-types listing sitting immediately above it in the SAME message uses the identical `- name: description` shape, so an unanchored scrape counts subagents as skills.

View Source
const ReminderEnd = "</system-reminder>"

ReminderEnd bounds the listing. Both this and Header appear literally in the JSON-escaped body (neither contains an escapable character), which is what lets a caller find the region with a byte search and no unescaping.

View Source
const RemovePrefix = "skill__"

RemovePrefix marks a declaration-removal entry as a SKILL rather than a tool.

A skill needs its own namespace in that list because the two are removed from different places and a bare name cannot say which is meant: a tool is an element of the top-level `tools` array, a skill is a line of prose inside a transcript message. They can also collide — nothing stops a skill being called `Monitor` — and the wrong mechanism on a name is a silent no-op, so the prefix is required rather than inferred. It mirrors `mcp__<server>`, which the same list already uses for "a whole MCP server, not one of its tools".

It lives HERE, and not beside the rewrite that acts on it, because the component that validates the list (components/reformat) and the code that applies it (apply) cannot import each other — apply imports the components. A shared constant beats two spellings of the same string.

Variables

This section is empty.

Functions

func EntryName

func EntryName(line string) (string, bool)

EntryName reads a listing line's skill name, or reports that the line is not an entry.

The delimiter is `": "` and only `": "`, because a colon can also be part of the name — a plugin skill is `plugin:skill`, a directory-scoped one `apps/web:deploy`. So the name is everything up to the first `": "`, and a line with no `": "` at all is a name on its own.

That last case is not hypothetical and is why this does not require a delimiter: a skill whose description is empty is listed as a bare `- security-review`, and on a real captured prompt 15 of 39 entries had that shape — one of them (`- ui-ux-pro-max:brand`) carrying a colon that is the plugin separator rather than a delimiter. An unrecognised line is not skipped, it is ABSORBED into the previous entry's span by Parse, so the previous entry answers for a name that is not its own — and a declaration filter acting on that entry then cuts every line it swallowed. One real entry swallowed 14 names.

The charset is the whole gate on a name-only line, and it is NOT sufficient — measured, not feared. A column-0 one-word bullet inside a description ("- charts", "- optional", "- Note") parses as a name here and would split the entry it belongs to. There is no lexical fix: 47 of 245 real skill names in production are bare words with no separator — loop, simplify, run, report, tools, gate — so `- report` (a real skill) and `- Note` (prose) are the same string shape, and any test that rejects one rejects the other. Tightening the charset would drop 19% of real names to avoid a class of line whose incidence cannot be measured, because the listing text is never stored (0 of 400,000 captured content rows carry the header).

So the discriminator is POSITION, and it lives in Parse, which has the neighbours: a name-only line whose successor is an indented continuation is prose, because a name-only entry has no description to continue. That closes the realistic case — a URL on its own line inside a description, which ValidName admits precisely because `plugin:skill` and `apps/web:deploy` need ':' and '/'.

ponytail: a one-word prose bullet with NO continuation after it still parses as an entry. Unclosable by spelling, and measured at zero incidence: 0 of 95 installed SKILL.md files contain a space-free description bullet. Upgrade path is a structurally marked listing, not a narrower charset — which would drop 19% of real names. Against the alternative: leaving the delimiter required drops 15 of 39 real entries and makes the removal switch cut 15 while reporting 1, which is the defect this exists to fix.

func ValidName

func ValidName(s string) bool

ValidName reports whether s is drawn from the charset a skill name uses. Anything else is not a name this package recognises, and is skipped rather than guessed at — the listing is the authority for what may be removed from a real request.

Types

type Entry

type Entry struct {
	Name string
	// From / To are the half-open line range this entry occupies in Listing.Lines.
	From, To int
}

Entry is one skill in the listing, as a LINE RANGE rather than a byte span.

Lines, because the two callers want different bytes from the same range and a span would have forced one of them to adjust it: the inventory joins the range with "\n" and stores that as the entry's text (so the entry's measured weight excludes its trailing newline), while the filter drops the lines and re-joins what is left. Both are exact on the same Listing.Lines.

type Listing

type Listing struct {
	Lines   []string
	Entries []Entry
}

Listing is a parsed listing body: its lines, and one Entry per skill.

func Parse

func Parse(body string) Listing

Parse splits a listing BODY — the text after Header and before ReminderEnd — into entries.

An entry runs from its own `- name:` line to the next line that parses as a name, not to the next blank line and not to the next line starting with "- ": a description containing its own "\n- " bullet would otherwise truncate the entry, and several real skill descriptions do exactly that.

func (Listing) Text

func (l Listing) Text(e Entry) string

Text is one entry's own text, joined the way the inventory stores and measures it.

func (Listing) Without

func (l Listing) Without(drop map[string]bool) (string, int)

Without returns the listing body with the named entries' lines removed, and how many entries went. The result is byte-exact when nothing is dropped, because Parse split on "\n" and this re-joins on "\n" — which is what lets a caller treat "removed nothing" as "changed nothing" rather than having to compare the strings.

Jump to

Keyboard shortcuts

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