skilltree

package
v0.17.5 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package skilltree owns the one canonical definition of an Agent Skill's content: which filesystem nodes belong to a skill, how they are hashed, how they are materialized, and how two divergent versions are merged.

Every skill content operation — import, local change detection, pull merge, push delta, and ordinary projection — reads trees through this package so a permissive copier can never drift from the strict import policy.

Index

Constants

View Source
const SkillManifestName = "SKILL.md"

SkillManifestName is the canonical skill manifest filename. Every source tier requires it exactly; no lowercase fallback is accepted.

Variables

This section is empty.

Functions

func HasManifest

func HasManifest(tree Tree) bool

HasManifest reports whether a tree carries a root-level canonical SKILL.md. Wildcard selectors use it to ignore ordinary directories.

func IsIgnoredName

func IsIgnoredName(name string) bool

IsIgnoredName reports whether a filesystem entry is one of the three source artifacts excluded from every canonical skill-tree read.

func Materialize

func Materialize(tree Tree, dir string) error

Materialize writes the tree into dir, which must already exist and is expected to be an empty staging directory owned by the caller. It never writes outside dir.

func Merge

func Merge(base, local, remote Tree, mergeText TextMerger) (Tree, []Conflict, error)

Merge reconciles local and remote against their common base.

A path changed on only one side applies cleanly, identical changes on both sides coalesce, compatible text changes are merged by mergeText, and every remaining divergence is reported as a conflict rather than resolved by preference. Renames are handled as the deletion plus addition they are recorded as, because a skill tree carries no rename metadata.

Merge never partially applies: when any conflict is reported the returned tree must be discarded by the caller.

func NormalizeName

func NormalizeName(value string) string

NormalizeName applies the same Unicode normalization used when comparing skill names across configuration, imports, and user-managed sources.

func ValidateRelativePath

func ValidateRelativePath(value string) error

ValidateRelativePath rejects any tree path that could escape its skill root.

Types

type Conflict

type Conflict struct {
	Path string
	Kind ConflictKind
}

Conflict reports one unmergeable path.

func (Conflict) Error

func (c Conflict) Error() string

Error renders a stable single-line conflict description.

type ConflictKind

type ConflictKind string

ConflictKind names why a path could not be reconciled automatically.

const (
	// ConflictContent means both sides changed the same text file
	// incompatibly.
	ConflictContent ConflictKind = "content"
	// ConflictDeleteModify means one side deleted a path the other changed.
	ConflictDeleteModify ConflictKind = "delete/modify"
	// ConflictBinary means both sides changed a non-text file differently.
	ConflictBinary ConflictKind = "binary"
	// ConflictMode means both sides changed the executable bit differently.
	ConflictMode ConflictKind = "mode"
)

type Diff

type Diff struct {
	Added    []string
	Modified []string
	Deleted  []string
}

Diff reports the paths added, modified, and deleted going from base to next.

func Compare

func Compare(base, next Tree) Diff

Compare returns the file-level delta from base to next.

func (Diff) Changed

func (d Diff) Changed() []string

Changed returns every changed path in sorted order.

func (Diff) IsEmpty

func (d Diff) IsEmpty() bool

IsEmpty reports whether the two trees carry identical content.

type FS

type FS interface {
	Lstat(name string) (os.FileInfo, error)
	ReadDir(name string) ([]os.DirEntry, error)
	ReadFile(name string) ([]byte, error)
}

FS is the filesystem surface a tree read needs. It is deliberately small so the sync package's injectable System and a plain OS implementation both satisfy it.

type File

type File struct {
	// Path is the slash-normalized path relative to the skill root.
	Path string
	// Data is the file's exact bytes.
	Data []byte
	// Executable records whether the owner execute bit is set. Git uses that
	// bit to choose between blob modes 100644 and 100755.
	Executable bool
}

File is one regular file in a skill tree.

func (File) FileMode

func (f File) FileMode() os.FileMode

FileMode returns the permission bits used when materializing a tree file.

type OSFS

type OSFS struct{}

OSFS reads through the real filesystem.

func (OSFS) Lstat

func (OSFS) Lstat(name string) (os.FileInfo, error)

Lstat returns file information without following symlinks.

func (OSFS) ReadDir

func (OSFS) ReadDir(name string) ([]os.DirEntry, error)

ReadDir lists a directory's entries.

func (OSFS) ReadFile

func (OSFS) ReadFile(name string) ([]byte, error)

ReadFile returns a file's exact bytes.

type SkillInfo

type SkillInfo struct {
	// Name is the frontmatter name, which must equal the selected directory
	// name and becomes the local imported directory name.
	Name string
	// Description is the required nonempty frontmatter description.
	Description string
}

SkillInfo is the identity a validated skill tree carries.

func ValidateManifest

func ValidateManifest(manifest []byte, sourcePath string) (SkillInfo, error)

ValidateManifest applies the same strict rules to one manifest's bytes.

Callers that already hold the manifest use it to apply the same identity and metadata rules without constructing a second tree. sourcePath names the skill root.

func ValidateSkill

func ValidateSkill(tree Tree, sourcePath string) (SkillInfo, error)

ValidateSkill enforces Agent Layer's strict skill rules on a tree that was selected at sourcePath.

It requires a canonical SKILL.md at the tree root, valid required metadata, a safe skill name, a name matching the selected directory, and frontmatter Agent Layer can project faithfully. sourcePath is used for error context and to derive the expected name.

type TextMerger

type TextMerger func(base, local, remote []byte) (merged []byte, conflicted bool, err error)

TextMerger performs a three-way merge of text content. It returns the merged bytes and whether the merge produced conflicts. An error means the merge could not be attempted at all.

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree is a skill's complete regular-file content, sorted by path.

Directories are intentionally absent: an empty directory carries no skill content and is not representable in Git, so including it would make local and upstream hashes disagree for identical skills.

func NewTree

func NewTree(files []File) (Tree, error)

NewTree builds a tree from files, sorting them and rejecting duplicates.

func Read

func Read(fsys FS, dir string) (Tree, error)

Read enumerates the skill tree rooted at dir.

It walks with Lstat so a link is classified without being followed, includes every regular file (hidden files included), ignores only `.git`, `.DS_Store`, and `Thumbs.db`, and rejects every other node type. A missing root directory yields an empty tree so callers can distinguish "no content" from a read failure by checking the directory themselves.

func (Tree) Equal

func (t Tree) Equal(other Tree) bool

Equal reports whether two trees carry identical content.

func (Tree) File

func (t Tree) File(filePath string) (File, bool)

File returns the file recorded at a path.

func (Tree) Files

func (t Tree) Files() []File

Files returns a detached copy of the tree's files in sorted path order.

func (Tree) Hash

func (t Tree) Hash() string

Hash returns the canonical content hash: sorted slash-normalized relative paths, exact file bytes, and the executable bit. The encoding is length-prefixed so no combination of paths and content can collide by concatenation.

func (Tree) IsEmpty

func (t Tree) IsEmpty() bool

IsEmpty reports whether the tree holds no files.

func (Tree) Len

func (t Tree) Len() int

Len returns the number of files in the tree.

func (Tree) Paths

func (t Tree) Paths() []string

Paths returns every file path in sorted order.

Jump to

Keyboard shortcuts

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