skills

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package skills contains the filesystem and validation logic for the folder-shaped Agent Skills format (agentskills.io): SKILL.md frontmatter validation, bundled-file discovery, and safe path handling for downloads.

Index

Constants

View Source
const (
	// MaxSkillMDBytes is the backend limit for the literal SKILL.md payload.
	MaxSkillMDBytes = 1 << 20 // 1 MB
	// MaxFileBytes is the backend per-file limit for bundled resources.
	MaxFileBytes = 100 << 20 // 100 MB
)

Variables

This section is empty.

Functions

func PlanReconstruct added in v0.6.0

func PlanReconstruct(dir string, b Bundle) (skillMDDest string, fileDests []string, err error)

PlanReconstruct validates every manifest path against dir using SafeJoin and returns the resolved destination for SKILL.md plus each bundled file. It writes nothing — callers use it for dry-run previews and to fail fast on a malicious path before any directory is created.

The returned slice is aligned with b.Files; the SKILL.md destination is returned separately as it is not part of the bundle manifest.

func ReadSkillMD

func ReadSkillMD(folder string) ([]byte, error)

ReadSkillMD reads the literal SKILL.md bytes from a skill folder root, returning friendly errors for the common failure modes.

func SafeJoin

func SafeJoin(dir, relPath string) (string, error)

SafeJoin joins a server-supplied manifest path onto a local destination directory, refusing absolute paths, backslashes, and any path that would escape dir.

func ValidateName

func ValidateName(name string) error

ValidateName checks the SKILL.md frontmatter `name` field against the backend rule and returns a friendly error when it does not conform.

Types

type Bundle added in v0.6.0

type Bundle struct {
	RawSkillMD string
	Files      []BundleFile
}

Bundle is the resolved content of a skill ready to be written to disk: the literal SKILL.md bytes plus its bundled files.

type BundleFile added in v0.6.0

type BundleFile struct {
	Path        string
	DownloadURL string
	SizeBytes   int64
}

BundleFile describes one bundled file in a skill's manifest as returned by the skills resolve endpoints: a relative forward-slash Path, a presigned DownloadURL, and the SizeBytes the server reported for it.

type Downloader added in v0.6.0

type Downloader func(url, dest string) error

Downloader fetches the contents of a presigned URL into dest, creating parent directories as needed. Callers inject their own implementation so the skills package stays free of cobra/HTTP-context concerns.

type File

type File struct {
	// Path is the manifest path: relative to the skill folder root, with
	// forward slashes.
	Path string
	// AbsPath is the on-disk location of the file.
	AbsPath string
	// Size is the file size in bytes.
	Size int64
}

File is one bundled asset discovered inside a skill folder.

func Walk

func Walk(root string) ([]File, error)

Walk discovers the bundled files of a skill folder. It skips the root SKILL.md (uploaded separately as the skill body), dotfiles, and dot directories (.git, .DS_Store, …), and returns entries sorted by path.

type Frontmatter

type Frontmatter struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
}

Frontmatter holds the SKILL.md fields the CLI surfaces. Parsing never rewrites the markdown — the literal bytes are uploaded as-is.

func ParseFrontmatter

func ParseFrontmatter(md []byte) (*Frontmatter, error)

ParseFrontmatter extracts the YAML frontmatter block from raw SKILL.md bytes. The file must start with a `---` line closed by another `---` line.

type WrittenFile added in v0.6.0

type WrittenFile struct {
	// Dest is the absolute (or dir-relative) on-disk path written.
	Dest string
	// SizeBytes is the reported size of the file (0 for SKILL.md, where the
	// literal byte length is used instead).
	SizeBytes int64
}

WrittenFile records one file written to disk during a reconstruction.

func Reconstruct added in v0.6.0

func Reconstruct(dir string, b Bundle, download Downloader) ([]WrittenFile, error)

Reconstruct writes a skill bundle into dir: it creates dir, writes SKILL.md verbatim, and downloads every bundled file via download. Every manifest path is validated with SafeJoin before any write happens, so a malicious path aborts the whole operation instead of leaving a partial folder behind.

It returns the list of files written (SKILL.md first, then bundled files in manifest order) so callers can print a per-file summary.

Jump to

Keyboard shortcuts

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