Files
skm/internal/manifest/manifest.go
T
johannesandClaude Sonnet 5.5 df8d11d8cb feat: pin agent definitions next to skills
A source can install agents (agents/<name>.md files with a frontmatter
name) alongside or instead of skills.

- manifest: optional "agents" selection; lock: "agents" map
- add --agent / --all-agents, remove --agent, list shows the kind
- check/update diff agents like skills (files, not directories)
- dashboard lists and removes agents
- home-manager module: agentTargets (default .claude/agents) links <name>.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 13:42:45 +01:00

106 lines
2.5 KiB
Go

// Package manifest is skills.json: the sources and skills you want.
package manifest
import (
"encoding/json"
"fmt"
"skill-manager/internal/jsonfile"
)
type Manifest struct {
Sources map[string]*Source `json:"sources"`
}
type Source struct {
// URL is a flake ref, e.g. github:owner/repo or git+ssh://git@host/user/repo.
URL string `json:"url"`
// Ref is the branch or tag to track; empty means the default branch.
Ref string `json:"ref,omitempty"`
Skills Selection `json:"skills"`
// Agents are subagent definitions (agents/<name>.md files). Path, when set, is the file.
Agents Selection `json:"agents,omitzero"`
}
// Empty reports whether the source installs nothing.
func (s *Source) Empty() bool {
return !s.Skills.All && len(s.Skills.Items) == 0 && !s.Agents.All && len(s.Agents.Items) == 0
}
// Selection is either "*" (everything of its kind in the repo) or a list of names.
type Selection struct {
All bool
Items []Skill
}
// Skill names a skill in its repo and optionally renames it on install.
type Skill struct {
Name string `json:"name"`
// Path picks one skill when the repo has several with this name.
Path string `json:"path,omitempty"`
As string `json:"as,omitempty"`
}
// Installed is the name the skill gets on disk.
func (k Skill) Installed() string {
if k.As != "" {
return k.As
}
return k.Name
}
func Load(path string) (*Manifest, error) {
m := &Manifest{}
if _, err := jsonfile.Read(path, m); err != nil {
return nil, err
}
if m.Sources == nil {
m.Sources = map[string]*Source{}
}
return m, nil
}
func (m *Manifest) Save(path string) error {
return jsonfile.Write(path, m)
}
func (s Selection) MarshalJSON() ([]byte, error) {
if s.All {
return json.Marshal("*")
}
if s.Items == nil {
return []byte("[]"), nil
}
return json.Marshal(s.Items)
}
func (s *Selection) UnmarshalJSON(b []byte) error {
var str string
if json.Unmarshal(b, &str) == nil {
if str != "*" {
return fmt.Errorf(`skills must be "*" or a list, got %q`, str)
}
*s = Selection{All: true}
return nil
}
*s = Selection{}
return json.Unmarshal(b, &s.Items)
}
// A skill is written as "name", or as an object when it has a path or alias.
func (k Skill) MarshalJSON() ([]byte, error) {
if k.As == "" && k.Path == "" {
return json.Marshal(k.Name)
}
type plain Skill
return json.Marshal(plain(k))
}
func (k *Skill) UnmarshalJSON(b []byte) error {
if json.Unmarshal(b, &k.Name) == nil {
return nil
}
type plain Skill
return json.Unmarshal(b, (*plain)(k))
}