Documentation
¶
Overview ¶
Package skill renders and installs the agent skill embedded in the binary (skills/ytrack), stamped with the binary's version so an installed skill always describes the ytrack that installed it.
Index ¶
- Constants
- Variables
- func DefaultDirs() ([]string, error)
- func Files() fs.FS
- func HomeDirs() ([]string, error)
- func Install(root, version string) (string, error)
- func InstallNoWait(root, version string) (string, error)
- func Lock(wait time.Duration) (unlock func(), ok bool)
- func Managed(dir string) bool
- func RegistryPath() (string, error)
- func Render(version string) ([]byte, error)
- func TryLock() (unlock func(), ok bool)
- func Uninstall(root string) (bool, error)
- type Copy
- type ForeignError
- type Meta
- type Registry
- func (r *Registry) Clone() *Registry
- func (r *Registry) Copies(version string) []Copy
- func (r *Registry) Dirty() bool
- func (r *Registry) Equal(o *Registry) bool
- func (r *Registry) Forget(dir string) bool
- func (r *Registry) Record(dir string) bool
- func (r *Registry) Save() error
- func (r *Registry) Sync(version string) ([]SyncResult, bool)
- func (r *Registry) SyncNoWait(version string) ([]SyncResult, bool)
- type SyncResult
Constants ¶
const ( StateCurrent = "current" // holds the skill at the running version StateStale = "stale" // holds the skill at another version StateMissing = "missing" // holds no ytrack skill (deleted or replaced) )
Copy states.
const ( SyncUpdated = "updated" // rewritten at the version SyncDropped = "dropped" // missing or replaced by something else; forgotten SyncManual = "manual" // a repository copy; left as it is SyncFailed = "failed" // could not be rewritten; still recorded )
Sync outcomes.
const EntryFile = "SKILL.md"
EntryFile is the skill's entry point inside its directory.
const Name = "ytrack"
Name is the skill's name: its directory and its frontmatter name.
Variables ¶
var ErrBusy = errors.New("another install is updating this skill directory")
ErrBusy reports that InstallNoWait found another install working on the directory and left it alone.
Functions ¶
func DefaultDirs ¶ added in v0.6.0
DefaultDirs returns the directories `ytrack skill install` writes without --dir: ~/.agents/skills, which Codex, Cursor, OpenCode and Pi read, and ~/.claude/skills, which Claude Code reads.
func HomeDirs ¶ added in v0.6.0
HomeDirs returns the home-level skills directories of the agents ytrack knows, in adoption order: ~/.agents/skills first, as `npx skills add` keeps its canonical copy there and links the others to it.
func Install ¶
Install writes the skill, stamped with version, to <root>/ytrack and returns that directory. root is created when missing. An existing <root>/ytrack is replaced only when its SKILL.md has "name: ytrack"; anything else there is refused with a *ForeignError and left untouched. A symlinked <root>/ytrack (as `npx skills add` makes) is followed and its target updated.
The new copy is written to a temporary sibling directory and renamed into place, so a failed install leaves the earlier skill as it was. Installs racing on one directory (two ytrack processes refreshing the same copy) all succeed and leave one complete copy and no temporary directories.
func InstallNoWait ¶ added in v0.6.0
InstallNoWait is Install for the background refresh, which must never delay a command: when another install holds the directory it returns ErrBusy at once and changes nothing.
func Lock ¶ added in v0.6.0
Lock takes the registry lock, waiting up to wait for another process to release it. It reports false at once when the lock cannot be made at all.
func Managed ¶ added in v0.6.0
Managed reports whether ytrack keeps the copy in skills directory dir at its own version: dir is one of HomeDirs, or under the home directory and not inside a git work tree. A copy in a repository is the repository's: it changes only through ytrack skill install --dir.
func RegistryPath ¶ added in v0.6.0
RegistryPath returns the registry file's path.
func TryLock ¶ added in v0.6.0
func TryLock() (unlock func(), ok bool)
TryLock takes the registry lock without waiting. It reports false when another process holds it or the lock cannot be made (a read-only state directory); the caller then skips its work.
Types ¶
type Copy ¶ added in v0.6.0
type Copy struct {
Dir string // the skills directory
Path string // Dir/ytrack
Version string // metadata.version of its SKILL.md; empty when missing
State string // StateCurrent, StateStale or StateMissing
// Managed reports whether ytrack keeps the copy at its version (see
// Managed); a copy in a repository is updated by hand.
Managed bool
}
Copy is a recorded skill copy as found on disk.
type ForeignError ¶
type ForeignError struct{ Dir string }
ForeignError reports a skill directory that Install will not replace because it does not hold the ytrack skill.
func (*ForeignError) Error ¶
func (e *ForeignError) Error() string
type Meta ¶
type Meta struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Metadata map[string]string `yaml:"metadata"`
}
Meta is the SKILL.md frontmatter.
type Registry ¶ added in v0.6.0
type Registry struct {
// Synced is the version of the last sync that rewrote every copy.
Synced string `yaml:"synced,omitempty"`
// Dirs are absolute skills directories; each holds <dir>/ytrack.
Dirs []string `yaml:"dirs"`
// contains filtered or unexported fields
}
Registry is the list of skills directories holding a copy of the skill that ytrack installed or adopted, and the version every copy it keeps up to date was last synced to.
func OpenRegistry ¶ added in v0.6.0
OpenRegistry reads the registry. While the file does not exist yet, the registry adopts every home-level directory (HomeDirs) that holds the ytrack skill already, never one holding anything else, stamped Synced with the newest version among them; Save then creates the file.
func (*Registry) Dirty ¶ added in v0.6.0
Dirty reports whether the registry holds anything its file does not: copies adopted while the file did not exist yet.
func (*Registry) Equal ¶ added in v0.6.0
Equal reports whether two registries record the same thing.
func (*Registry) Forget ¶ added in v0.6.0
Forget removes dir, made absolute, and reports whether it was recorded.
func (*Registry) Record ¶ added in v0.6.0
Record adds the skills directory dir, made absolute, and reports whether the registry changed. Directories whose ytrack copy is the same one (one copy symlinked into several directories, as `npx skills add` does) are recorded once; the directory holding the copy itself is preferred over one holding a link to it.
func (*Registry) Save ¶ added in v0.6.0
Save writes the registry: to a temporary file renamed into place, so a concurrent reader sees the old file or the new one, never a torn one.
func (*Registry) Sync ¶ added in v0.6.0
func (r *Registry) Sync(version string) ([]SyncResult, bool)
Sync rewrites every managed copy at version and forgets every recorded directory whose copy is gone or holds something else: a missing copy is never re-created. Copies in repositories are left alone. When every managed copy was rewritten, Synced becomes version. It reports what it did per directory, and whether it all succeeded. The caller saves the registry.
func (*Registry) SyncNoWait ¶ added in v0.6.0
func (r *Registry) SyncNoWait(version string) ([]SyncResult, bool)
SyncNoWait is Sync for the background refresh: a copy another install is updating is skipped (SyncFailed with ErrBusy, so Synced stays and the next run retries) instead of waited for.
type SyncResult ¶ added in v0.6.0
SyncResult is what Sync did with one recorded directory.