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>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-28 13:42:45 +01:00
1 parent 0aedef8c8c
commit df8d11d8cb
15 files changed
+648 -131

No files matched your search

+77 -21
View File
@@ -31,15 +31,25 @@ func (k ChangeKind) Symbol() string {
return [...]string{"↑", "+", "-"}[k]
}
// Change is one installed skill that differs between the lock and upstream.
// Change is one installed skill or agent that differs between the lock and upstream.
type Change struct {
Name string
Kind ChangeKind
// Skill directories in the store; empty when added or removed, and Old is
// also empty for a source dropped from the manifest.
// Agent is set for an agent definition, whose Old and New are files, not directories.
Agent bool
// Skill directories (or agent files) in the store; empty when added or removed,
// and Old is also empty for a source dropped from the manifest.
Old, New string
}
// Label is Name, marked when the change is an agent.
func (c Change) Label() string {
if c.Agent {
return "agent " + c.Name
}
return c.Name
}
// SourceStatus compares a source's lock entry with the head of its ref.
type SourceStatus struct {
Source string
@@ -91,7 +101,7 @@ func selectSources(m *manifest.Manifest, l *lock.Lock, names []string) ([]string
for _, name := range names {
key, ok := owner(m, l, name)
if !ok {
return nil, fmt.Errorf("no source or installed skill %q", name)
return nil, fmt.Errorf("no source or installed skill or agent %q", name)
}
picked[key] = true
}
@@ -110,9 +120,13 @@ func owner(m *manifest.Manifest, l *lock.Lock, name string) (string, bool) {
if _, ok := src.Skills[name]; ok {
return key, true
}
if _, ok := src.Agents[name]; ok {
return key, true
}
}
for key, src := range m.Sources {
if slices.ContainsFunc(src.Skills.Items, func(k manifest.Skill) bool { return k.Installed() == name }) {
named := func(k manifest.Skill) bool { return k.Installed() == name }
if slices.ContainsFunc(src.Skills.Items, named) || slices.ContainsFunc(src.Agents.Items, named) {
return key, true
}
}
@@ -131,6 +145,9 @@ func (s Store) check(ctx context.Context, key string, src *manifest.Source, lock
for _, name := range slices.Sorted(maps.Keys(locked.Skills)) {
st.Changes = append(st.Changes, Change{Name: name, Kind: Removed})
}
for _, name := range slices.Sorted(maps.Keys(locked.Agents)) {
st.Changes = append(st.Changes, Change{Name: name, Kind: Removed, Agent: true})
}
return st
}
@@ -150,31 +167,60 @@ func (s Store) check(ctx context.Context, key string, src *manifest.Source, lock
}
st.NewRev = res.Rev()
found, err := skills.Discover(res.StorePath)
var agents []skills.Skill
if err == nil {
agents, err = skills.DiscoverAgents(res.StorePath)
}
if err == nil {
st.next = &lock.Source{Locked: res.Locked}
st.next.Skills, err = resolve(src.Skills, found)
st.next.Skills, err = resolve(src.Skills, found, "skill")
}
if err == nil {
st.next.Agents, err = resolve(src.Agents, agents, "agent")
}
if err != nil {
st.Err = err
return st
}
names := slices.Sorted(maps.Keys(locked.Skills))
for name := range st.next.Skills {
if _, ok := locked.Skills[name]; !ok {
for _, kind := range []struct {
old, new map[string]string
agent bool
}{
{locked.Skills, st.next.Skills, false},
{locked.Agents, st.next.Agents, true},
} {
changes, err := compare(ctx, kind.old, kind.new, oldRoot, res.StorePath, kind.agent)
if err != nil {
st.Err = err
return st
}
st.Changes = append(st.Changes, changes...)
}
return st
}
// compare lists the entries of one kind that differ between the locked paths (in
// oldRoot) and the resolved ones (in newRoot), sorted by name.
func compare(ctx context.Context, locked, next map[string]string, oldRoot, newRoot string, agent bool) ([]Change, error) {
names := slices.Sorted(maps.Keys(locked))
for name := range next {
if _, ok := locked[name]; !ok {
names = append(names, name)
}
}
slices.Sort(names)
var out []Change
for _, name := range names {
oldPath, wasLocked := locked.Skills[name]
newPath, stays := st.next.Skills[name]
ch := Change{Name: name}
oldPath, wasLocked := locked[name]
newPath, stays := next[name]
ch := Change{Name: name, Agent: agent}
if wasLocked {
ch.Old = filepath.Join(oldRoot, oldPath)
}
if stays {
ch.New = filepath.Join(res.StorePath, newPath)
ch.New = filepath.Join(newRoot, newPath)
}
switch {
case !stays:
@@ -184,17 +230,16 @@ func (s Store) check(ctx context.Context, key string, src *manifest.Source, lock
default:
same, err := sameDir(ctx, ch.Old, ch.New)
if err != nil {
st.Err = err
return st
return nil, err
}
if same {
continue
}
ch.Kind = Modified
}
st.Changes = append(st.Changes, ch)
out = append(out, ch)
}
return st
return out, nil
}
// Apply writes the lock entries of the outdated statuses.
@@ -232,7 +277,7 @@ func CommitMessage(applied []SourceStatus) string {
heads = append(heads, fmt.Sprintf("update %s %.7s→%.7s", st.Source, st.OldRev, st.NewRev))
}
for _, ch := range st.Changes {
body = append(body, ch.Kind.Symbol()+" "+ch.Name)
body = append(body, ch.Kind.Symbol()+" "+ch.Label())
}
}
return "skills: " + strings.Join(heads, ", ") + "\n\n" + strings.Join(body, "\n")
@@ -240,9 +285,20 @@ func CommitMessage(applied []SourceStatus) string {
// Diff renders a change as a unified diff with a/<name> and b/<name> paths.
func Diff(ctx context.Context, ch Change) (string, error) {
empty, err := os.MkdirTemp("", "skm-empty-")
if err != nil {
return "", err
// An added or removed agent is a file, so it needs an empty file to compare with.
var empty string
if ch.Agent {
f, err := os.CreateTemp("", "skm-empty-")
if err != nil {
return "", err
}
f.Close()
empty = f.Name()
} else {
var err error
if empty, err = os.MkdirTemp("", "skm-empty-"); err != nil {
return "", err
}
}
defer os.Remove(empty)
oldDir, newDir := cmp.Or(ch.Old, empty), cmp.Or(ch.New, empty)