Documentation
¶
Overview ¶
Package skill is the gofer-side skill library (JOB-10, design docs/design/2026-09-23-skills-binding-and-comment-routing-design.md §一): a skill is a directory of "working method" knowledge — a required SKILL.md plus attachments — that lives WITH THE SERVER, not in the project tree, so a job can be handed it without a concurrent job seeing it and without git ever tracking it.
One directory per skill, under a root the caller chooses (<config-dir>/skills by convention):
<root>/<name>/SKILL.md required <root>/<name>/<any attachment> scripts, references, templates…
The library is a directory tree; the SQLite index (the Repo seam) only holds metadata plus a sha256 per file, so `skill ls` / `skill update` never have to re-hash a skill to answer "what is in the library" or "what changed upstream".
Three properties are deliberate and load-bearing:
- A skill is knowledge, not a program. Import drops every exec bit (0644) and refuses symlinks; the agent runs a script by naming an interpreter, exactly like any other file it reads.
- An archive is untrusted input. Every extracted path is resolved through safeJoin (escape refused, absolute/drive-letter names refused on every platform), and per-file / total byte caps are enforced while reading, not from the archive's own size fields.
- A failed import never damages the library. Everything is materialised and validated inside a temp dir UNDER the store root first (so the final step is a same-filesystem rename); only then does it replace the previous copy, and the index row is written after the files are in place (Store.publish).
The package depends on nothing but the standard library and internal/util — the index is an interface (Repo), not a SQLite call — so it can be unit-tested without a database and adopted by the data layer without an import cycle. JobstoreRepo is the production wiring (jobstore's `skills` table).
Index ¶
- Variables
- type Change
- type File
- type Limits
- type Repo
- type Skill
- type Store
- func (s *Store) Dir(name string) string
- func (s *Store) Export(name string, w io.Writer) error
- func (s *Store) Get(name string) (Skill, bool, error)
- func (s *Store) Import(src, caller string) (Skill, error)
- func (s *Store) List() ([]Skill, error)
- func (s *Store) Mount(name, dstDir string) (int64, error)
- func (s *Store) Remove(name string) error
- func (s *Store) Root() string
- func (s *Store) Update(name, caller string) (Change, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("skill: not found") ErrInvalid = errors.New("skill: invalid skill") ErrEscape = errors.New("skill: path escapes the skill dir") ErrSymlink = errors.New("skill: symlinks are not allowed") ErrTooLarge = errors.New("skill: over the size limits") )
The failures a caller can act on. Everything else is an I/O error wrapped with context. They are separate sentinels because the CLI maps them to different exits/messages: "wrong name" and "the source is not a skill" are user errors, while ErrEscape/ErrSymlink/ErrTooLarge are a refused import.
Functions ¶
This section is empty.
Types ¶
type Change ¶
Change is what a re-fetch did to a skill: the paths added, changed and removed by the update, each in path order.
type File ¶
type File struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
Size int64 `json:"size,omitempty"`
}
File is one file of a skill, path relative to the skill dir, slash-separated. SHA256 is what lets `skill update` report "these files changed" without shipping bytes, and what the version hash is computed over.
type Limits ¶
Limits caps what a single skill may contain. They are checked while a source is being read (not against the size fields an archive reports about itself, which are attacker-controlled), so an oversized source is refused before it can fill the disk.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits is the shipped 2MiB per file / 10MiB per skill: a skill is prompt material, and past those sizes an agent cannot read it in one go anyway.
type Repo ¶
type Repo interface {
InsertSkill(Skill) error
UpdateSkill(Skill) error
GetSkill(name string) (Skill, bool, error)
ListSkills() ([]Skill, error)
DeleteSkill(name string) error
}
Repo is the skill index: five statements over one row per skill. It is an interface so the library can be tested (and stored) without SQLite; jobstore implements the same column set behind JobstoreRepo.
type Skill ¶
type Skill struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Source string `json:"source,omitempty"` // dir|zip|url|git — what it came from
SourceRef string `json:"source_ref,omitempty"` // the spec Update re-fetches verbatim
Version string `json:"version,omitempty"` // sha256 over the file list
Files []File `json:"files,omitempty"`
Size int64 `json:"size,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
}
Skill is one library entry: the metadata the index keeps, plus the file list the import was validated with. The bytes themselves live on disk (Store.Dir); this shadow copy is what makes listing and diffing possible without walking the tree.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the skill library: a root directory of skill dirs plus an index.
mu serialises every operation that reads or replaces a skill's tree. Import and Update are read-modify-write over both the filesystem and the index, and holding the lock for the whole operation is what makes "replace atomically" true; these are admin operations, so the cost of serialising them (a git clone under the lock) buys correctness we cannot get any other way.
func NewStore ¶
NewStore opens (creating if needed) the library at root. Callers pass <config-dir>/skills so the library is backed up with the config (design §一.1).
func (*Store) Dir ¶
Dir is the on-disk directory of one skill. It returns "" for a name that fails validation, so a caller that ignores the index (or a typo) can never be handed a path outside the store root.
func (*Store) Export ¶
Export streams the skill as a zip archive: entry names relative to the skill dir, slash-separated, so `skill export` output re-imports to the same tree.
Export owns the zip writer (it must Close it to emit the central directory) but never w and never Close()s it — the caller may be writing to a file, a buffer or a response body. On a walk error the writer is left under the caller's control with a partial archive on w: the caller discards it, exactly like any other failed stream.
func (*Store) Get ¶
Get returns the indexed skill. The bool is false (with a nil error) when the library has no such skill.
func (*Store) Import ¶
Import copies a source into the library under the name its SKILL.md declares (or the source's own basename) and indexes it. It accepts a local directory, a local .zip, an http(s) URL of a .zip, and git+https://…[#subdir] (the last two are fetched server-side; design §一.2).
Importing a name that already exists REPLACES it — that is the whole point of `skill import` being re-runnable — and the replacement is atomic in the sense that matters: the new tree is built and validated off to the side and only then swapped in (see publish), so a source that fails validation (no SKILL.md, escape, symlink, over the caps) leaves the previous skill exactly as it was.
func (*Store) Mount ¶
Mount copies the skill's tree into dstDir (created, parents included) and returns the bytes written. This is how a job actually gets a skill (design §一.4): the caller points dstDir at the job's PRIVATE directory — <result_dir>/skills/<name> on the executing machine — so the project working tree never sees it, concurrent jobs never share it, and the files expire with the job's result dir.
The destination must be disjoint from the skill dir: a dstDir inside the source would copy the tree into itself until the disk fills, and a dstDir that CONTAINS the source has the same effect from the other end. Both are refused rather than half-copied, which is also why an existing dstDir is written INTO (files overwritten, nothing pruned) instead of being replaced.
func (*Store) Remove ¶
Remove deletes the index row first and the directory second. That order is deliberate: the index is what `skill ls` and the binding resolver read, so a crash between the two steps leaves an orphan directory (invisible, reused by the next import of the same name) instead of an index row pointing at files that are gone.
func (*Store) Update ¶
Update re-fetches a skill from the source its index entry recorded and replaces the library copy, returning the file-level diff (by sha256). A skill imported before the source was recorded — or from a source that no longer resolves — cannot be updated and says so with ErrInvalid.