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:
1 parent
0aedef8c8c
commit
df8d11d8cb
15 files changed
+648
-131
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
**Pin agent skills from git repos with Nix, and update them only after you've reviewed the diff.**
|
**Pin agent skills from git repos with Nix, and update them only after you've reviewed the diff.**
|
||||||
|
|
||||||
`skm` manages [agent skills](https://docs.claude.com/en/docs/claude-code/skills) (directories containing a `SKILL.md`) that come from git repositories. Each repo is pinned to a commit and a Nix `narHash`. Nix fetches the pinned sources and home-manager links every skill into `~/.claude/skills` and `~/.agents/skills`. `skm` only ever edits two JSON files.
|
`skm` manages [agent skills](https://docs.claude.com/en/docs/claude-code/skills) (directories containing a `SKILL.md`) and subagent definitions (`agents/<name>.md` files) that come from git repositories. Each repo is pinned to a commit and a Nix `narHash`. Nix fetches the pinned sources and home-manager links every skill into `~/.claude/skills` and `~/.agents/skills`, and every agent into `~/.claude/agents`. `skm` only ever edits two JSON files.
|
||||||
|
|
||||||
- **Reproducible**: a lockfile with commit and hash for every source, evaluated by Nix.
|
- **Reproducible**: a lockfile with commit and hash for every source, evaluated by Nix.
|
||||||
- **Reviewed updates**: see the diff of every changed skill before it is applied.
|
- **Reviewed updates**: see the diff of every changed skill before it is applied.
|
||||||
@@ -58,6 +58,7 @@ Add the flake as an input and import its home-manager module:
|
|||||||
| `manifestDir` | | Directory holding `skills.json` and `skills.lock.json` |
|
| `manifestDir` | | Directory holding `skills.json` and `skills.lock.json` |
|
||||||
| `lockFile` | | The lockfile as a path inside your flake; pure evaluation can't read `manifestDir` |
|
| `lockFile` | | The lockfile as a path inside your flake; pure evaluation can't read `manifestDir` |
|
||||||
| `targets` | `[ ".claude/skills" ".agents/skills" ]` | Directories, relative to home, that get one symlink per skill |
|
| `targets` | `[ ".claude/skills" ".agents/skills" ]` | Directories, relative to home, that get one symlink per skill |
|
||||||
|
| `agentTargets` | `[ ".claude/agents" ]` | Directories, relative to home, that get one `<name>.md` symlink per agent |
|
||||||
| `switchCommand` | `""` | Command `skm update --switch` runs to apply a new lock |
|
| `switchCommand` | `""` | Command `skm update --switch` runs to apply a new lock |
|
||||||
| `package` | this flake's `skm` | The `skm` package to install |
|
| `package` | this flake's `skm` | The `skm` package to install |
|
||||||
|
|
||||||
@@ -88,7 +89,8 @@ In the diff review, `y` accepts a source, `n` skips it, and `tab`/`shift+tab` mo
|
|||||||
skm add github:mattpocock/skills # pick skills interactively
|
skm add github:mattpocock/skills # pick skills interactively
|
||||||
skm add github:mattpocock/skills --skill tdd,grilling=grilling-mp
|
skm add github:mattpocock/skills --skill tdd,grilling=grilling-mp
|
||||||
skm add git+ssh://git@host/me/skills --ref main --all
|
skm add git+ssh://git@host/me/skills --ref main --all
|
||||||
skm list # installed skills, source, short rev
|
skm add github:cursor/plugins --agent pstack/agents/comment-sicko.md=comment-sicko
|
||||||
|
skm list # installed skills and agents, source, short rev
|
||||||
skm outdated # changed, added and removed skills upstream
|
skm outdated # changed, added and removed skills upstream
|
||||||
skm update # review diffs, then write the lock
|
skm update # review diffs, then write the lock
|
||||||
skm update tdd --yes --switch # no review, then run switchCommand
|
skm update tdd --yes --switch # no review, then run switchCommand
|
||||||
@@ -98,9 +100,9 @@ skm import --diff # migrate from vercel's skil
|
|||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `add <url> [--ref R] [--name N] (--skill a,b=alias,dir/c \| --all)` | Prefetch a repo, choose skills, write manifest and lock. Adding to an existing source keeps its pin. |
|
| `add <url> [--ref R] [--name N] [--skill a,b=alias,dir/c \| --all] [--agent a,b=alias,dir/c.md \| --all-agents]` | Prefetch a repo, choose skills and/or agents, write manifest and lock. Adding to an existing source keeps its pin. |
|
||||||
| `remove <name>` / `remove --source <source>` | Remove one skill (and the source once it's empty), or a whole source |
|
| `remove <name>` / `remove --agent <name>` / `remove --source <source>` | Remove one skill or agent (and the source once it's empty), or a whole source |
|
||||||
| `list` | Installed skills with source, rev and path |
|
| `list` | Installed skills and agents with source, rev and path |
|
||||||
| `outdated [source\|skill...]` | Prefetch sources in parallel and report changes |
|
| `outdated [source\|skill...]` | Prefetch sources in parallel and report changes |
|
||||||
| `update [source\|skill...] [--yes] [--switch]` | Review and apply updates. Without a terminal, diffs are printed and confirmed on stdin. |
|
| `update [source\|skill...] [--yes] [--switch]` | Review and apply updates. Without a terminal, diffs are printed and confirmed on stdin. |
|
||||||
| `import [--from lock] [--local dir] [--diff]` | Import `~/.local/state/skills/.skill-lock.json` and compare against committed skill copies |
|
| `import [--from lock] [--local dir] [--diff]` | Import `~/.local/state/skills/.skill-lock.json` and compare against committed skill copies |
|
||||||
@@ -136,6 +138,8 @@ Non-goals: non-git sources (tarballs, registries, local paths), patches or overl
|
|||||||
- `"as"` renames a skill. Two skills with the same installed name are an error.
|
- `"as"` renames a skill. Two skills with the same installed name are an error.
|
||||||
- `"path"` picks a skill by directory, for repos that ship the same name twice.
|
- `"path"` picks a skill by directory, for repos that ship the same name twice.
|
||||||
- To hold one skill back, add a second source entry for the same repo with its own `ref`.
|
- To hold one skill back, add a second source entry for the same repo with its own `ref`.
|
||||||
|
- `"agents"` takes the same forms as `"skills"` (`"*"`, names, `"as"`, `"path"`) and is optional. An agent is a `.md` file directly inside a directory named `agents`, with a `name:` in its frontmatter; `"path"` is the file. Repos that ship the same agent twice (a Cursor and a Claude Code copy) need `"path"`. A source may install only agents (`"skills": []`).
|
||||||
|
- Updates review agents like skills: an agent counts as outdated only when its own file changes.
|
||||||
|
|
||||||
`skills.lock.json` (written by `skm`):
|
`skills.lock.json` (written by `skm`):
|
||||||
|
|
||||||
@@ -145,7 +149,8 @@ Non-goals: non-git sources (tarballs, registries, local paths), patches or overl
|
|||||||
"sources": {
|
"sources": {
|
||||||
"mattpocock": {
|
"mattpocock": {
|
||||||
"locked": { "type": "github", "owner": "mattpocock", "repo": "skills", "rev": "abc123…", "narHash": "sha256-…" },
|
"locked": { "type": "github", "owner": "mattpocock", "repo": "skills", "rev": "abc123…", "narHash": "sha256-…" },
|
||||||
"skills": { "tdd": "skills/tdd", "prototype": "skills/prototype", "grilling-mp": "skills/grilling" }
|
"skills": { "tdd": "skills/tdd", "prototype": "skills/prototype", "grilling-mp": "skills/grilling" },
|
||||||
|
"agents": { "comment-sicko": "pstack/agents/comment-sicko.md" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,6 +177,6 @@ The end-to-end tests create a temporary `git+file://` repo and need `nix` on `PA
|
|||||||
| `internal/core/` | add, remove, outdated, update and import operations |
|
| `internal/core/` | add, remove, outdated, update and import operations |
|
||||||
| `internal/fetch/` | `Fetcher` interface and the `nix flake prefetch` implementation |
|
| `internal/fetch/` | `Fetcher` interface and the `nix flake prefetch` implementation |
|
||||||
| `internal/manifest/`, `internal/lock/` | `skills.json` and `skills.lock.json` |
|
| `internal/manifest/`, `internal/lock/` | `skills.json` and `skills.lock.json` |
|
||||||
| `internal/skills/` | `SKILL.md` discovery and subtree comparison |
|
| `internal/skills/` | `SKILL.md` and agent definition discovery |
|
||||||
| `internal/tui/` | bubbletea dashboard, picker and diff review |
|
| `internal/tui/` | bubbletea dashboard, picker and diff review |
|
||||||
| `nix/module.nix` | home-manager module |
|
| `nix/module.nix` | home-manager module |
|
||||||
+53
-23
@@ -22,8 +22,8 @@ const usage = `usage: skm [--dir DIR] [command] [args]
|
|||||||
Without a command, skm opens the dashboard.
|
Without a command, skm opens the dashboard.
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
add <url> [--ref R] [--name N] (--skill a,b=alias,dir/c | --all)
|
add <url> [--ref R] [--name N] [--skill a,b=alias,dir/c | --all] [--agent a,b=alias,dir/c.md | --all-agents]
|
||||||
remove <name> | remove --source <source>
|
remove <name> | remove --agent <name> | remove --source <source>
|
||||||
list
|
list
|
||||||
outdated [source|skill...]
|
outdated [source|skill...]
|
||||||
update [source|skill...] [--yes] [--switch]
|
update [source|skill...] [--yes] [--switch]
|
||||||
@@ -146,6 +146,8 @@ func add(ctx context.Context, store core.Store, args []string) error {
|
|||||||
name := fs.String("name", "", "source name (default: owner/repo from the url)")
|
name := fs.String("name", "", "source name (default: owner/repo from the url)")
|
||||||
skillList := fs.String("skill", "", "comma-separated skill names or paths; rename with name=alias")
|
skillList := fs.String("skill", "", "comma-separated skill names or paths; rename with name=alias")
|
||||||
all := fs.Bool("all", false, "install every skill, including ones added upstream later")
|
all := fs.Bool("all", false, "install every skill, including ones added upstream later")
|
||||||
|
agentList := fs.String("agent", "", "comma-separated agent names or paths (agents/<name>.md); rename with name=alias")
|
||||||
|
allAgents := fs.Bool("all-agents", false, "install every agent definition, including ones added upstream later")
|
||||||
pos, err := parse(fs, args)
|
pos, err := parse(fs, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -154,20 +156,14 @@ func add(ctx context.Context, store core.Store, args []string) error {
|
|||||||
return errors.New("add takes exactly one url")
|
return errors.New("add takes exactly one url")
|
||||||
}
|
}
|
||||||
|
|
||||||
req := core.AddRequest{Name: *name, URL: pos[0], Ref: *ref, All: *all}
|
req := core.AddRequest{
|
||||||
for item := range strings.SplitSeq(*skillList, ",") {
|
Name: *name, URL: pos[0], Ref: *ref,
|
||||||
if item = strings.TrimSpace(item); item == "" {
|
All: *all, AllAgents: *allAgents,
|
||||||
continue
|
Skills: parseItems(*skillList), Agents: parseItems(*agentList),
|
||||||
}
|
|
||||||
ref, as, _ := strings.Cut(item, "=")
|
|
||||||
k := manifest.Skill{Name: ref, As: as}
|
|
||||||
if strings.Contains(ref, "/") {
|
|
||||||
k = manifest.Skill{Path: ref, As: as}
|
|
||||||
}
|
|
||||||
req.Skills = append(req.Skills, k)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !req.All && len(req.Skills) == 0 && tui.Interactive() {
|
wantsAgents := req.AllAgents || len(req.Agents) > 0
|
||||||
|
if !req.All && len(req.Skills) == 0 && !wantsAgents && tui.Interactive() {
|
||||||
found, installed, err := store.Available(ctx, req)
|
found, installed, err := store.Available(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -185,13 +181,21 @@ func add(ctx context.Context, store core.Store, args []string) error {
|
|||||||
|
|
||||||
key, err := store.Add(ctx, req)
|
key, err := store.Add(ctx, req)
|
||||||
if sel, ok := errors.AsType[*core.NoSelectionError](err); ok {
|
if sel, ok := errors.AsType[*core.NoSelectionError](err); ok {
|
||||||
fmt.Fprintf(os.Stderr, "skills in %s:\n", sel.Source)
|
|
||||||
w := tabwriter.NewWriter(os.Stderr, 0, 0, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stderr, 0, 0, 2, ' ', 0)
|
||||||
for _, s := range sel.Available {
|
if len(sel.Available) > 0 {
|
||||||
fmt.Fprintf(w, " %s\t%s\n", s.Name, s.Path)
|
fmt.Fprintf(w, "skills in %s:\n", sel.Source)
|
||||||
|
for _, s := range sel.Available {
|
||||||
|
fmt.Fprintf(w, " %s\t%s\n", s.Name, s.Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(sel.AvailableAgents) > 0 {
|
||||||
|
fmt.Fprintf(w, "agents in %s:\n", sel.Source)
|
||||||
|
for _, s := range sel.AvailableAgents {
|
||||||
|
fmt.Fprintf(w, " %s\t%s\n", s.Name, s.Path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
return errors.New("choose with --skill a,b (or a path for same-named skills) or --all")
|
return errors.New("choose with --skill a,b / --all, or --agent a,b / --all-agents (a path for same-named entries)")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -200,27 +204,49 @@ func add(ctx context.Context, store core.Store, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parseItems reads "a,b=alias,dir/c": names, or paths when they contain a slash.
|
||||||
|
func parseItems(list string) []manifest.Skill {
|
||||||
|
var out []manifest.Skill
|
||||||
|
for item := range strings.SplitSeq(list, ",") {
|
||||||
|
if item = strings.TrimSpace(item); item == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ref, as, _ := strings.Cut(item, "=")
|
||||||
|
k := manifest.Skill{Name: ref, As: as}
|
||||||
|
if strings.Contains(ref, "/") {
|
||||||
|
k = manifest.Skill{Path: ref, As: as}
|
||||||
|
}
|
||||||
|
out = append(out, k)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func remove(store core.Store, args []string) error {
|
func remove(store core.Store, args []string) error {
|
||||||
fs := flag.NewFlagSet("remove", flag.ContinueOnError)
|
fs := flag.NewFlagSet("remove", flag.ContinueOnError)
|
||||||
source := fs.String("source", "", "remove a whole source")
|
source := fs.String("source", "", "remove a whole source")
|
||||||
|
agent := fs.Bool("agent", false, "the name is an agent definition, not a skill")
|
||||||
pos, err := parse(fs, args)
|
pos, err := parse(fs, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case *source != "" && len(pos) == 0:
|
case *source != "" && len(pos) == 0 && !*agent:
|
||||||
if err := store.RemoveSource(*source); err != nil {
|
if err := store.RemoveSource(*source); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("removed source %s\n", *source)
|
fmt.Printf("removed source %s\n", *source)
|
||||||
case *source == "" && len(pos) == 1:
|
case *source == "" && len(pos) == 1:
|
||||||
key, err := store.Remove(pos[0])
|
rm := store.Remove
|
||||||
|
if *agent {
|
||||||
|
rm = store.RemoveAgent
|
||||||
|
}
|
||||||
|
key, err := rm(pos[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("removed %s (from %s)\n", pos[0], key)
|
fmt.Printf("removed %s (from %s)\n", pos[0], key)
|
||||||
default:
|
default:
|
||||||
return errors.New("remove takes one skill name, or --source")
|
return errors.New("remove takes one skill name, one name with --agent, or --source")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -234,9 +260,13 @@ func list(store core.Store, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||||
fmt.Fprintln(w, "NAME\tSOURCE\tREV\tPATH")
|
fmt.Fprintln(w, "NAME\tKIND\tSOURCE\tREV\tPATH")
|
||||||
for _, s := range installed {
|
for _, s := range installed {
|
||||||
fmt.Fprintf(w, "%s\t%s\t%.7s\t%s\n", s.Name, s.Source, s.Rev, s.Path)
|
kind := "skill"
|
||||||
|
if s.Agent {
|
||||||
|
kind = "agent"
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, "%s\t%s\t%s\t%.7s\t%s\n", s.Name, kind, s.Source, s.Rev, s.Path)
|
||||||
}
|
}
|
||||||
return w.Flush()
|
return w.Flush()
|
||||||
}
|
}
|
||||||
+1
-1
@@ -140,7 +140,7 @@ func printStatus(w io.Writer, st core.SourceStatus) {
|
|||||||
fmt.Fprintf(w, "%s %.7s → %.7s\n", st.Source, st.OldRev, st.NewRev)
|
fmt.Fprintf(w, "%s %.7s → %.7s\n", st.Source, st.OldRev, st.NewRev)
|
||||||
}
|
}
|
||||||
for _, ch := range st.Changes {
|
for _, ch := range st.Changes {
|
||||||
fmt.Fprintf(w, " %s %s\n", ch.Kind.Symbol(), ch.Name)
|
fmt.Fprintf(w, " %s %s\n", ch.Kind.Symbol(), ch.Label())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,227 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"skill-manager/internal/lock"
|
||||||
|
"skill-manager/internal/manifest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// withAgents adds pstack/agents/<name>.md files ("name" or "name:body") to a fixture root.
|
||||||
|
func withAgents(t *testing.T, root string, agents ...string) string {
|
||||||
|
t.Helper()
|
||||||
|
dir := filepath.Join(root, "pstack", "agents")
|
||||||
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, a := range agents {
|
||||||
|
name, body, _ := strings.Cut(a, ":")
|
||||||
|
text := "---\nname: " + name + "\ndescription: x\n---\n" + body + "\n"
|
||||||
|
if err := os.WriteFile(filepath.Join(dir, name+".md"), []byte(text), 0o644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return root
|
||||||
|
}
|
||||||
|
|
||||||
|
func agentStore(t *testing.T) (Store, *fakeFetcher) {
|
||||||
|
f := &fakeFetcher{repos: map[string]*fakeRepo{
|
||||||
|
"github:cursor/plugins": {head: "r1", revs: map[string]string{
|
||||||
|
"r1": withAgents(t, fixture(t, "tdd"), "comment-sicko:v1", "poteto-agent"),
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
return Store{Dir: t.TempDir(), Fetcher: f}, f
|
||||||
|
}
|
||||||
|
|
||||||
|
// agents builds manifest entries; "name=alias" renames.
|
||||||
|
func agents(items ...string) []manifest.Skill {
|
||||||
|
var out []manifest.Skill
|
||||||
|
for _, n := range items {
|
||||||
|
name, as, _ := strings.Cut(n, "=")
|
||||||
|
out = append(out, manifest.Skill{Name: name, As: as})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func lockedAgents(t *testing.T, s Store, key string) map[string]string {
|
||||||
|
t.Helper()
|
||||||
|
l, err := lock.Load(filepath.Join(s.Dir, LockFile))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return l.Sources[key].Agents
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddAgentsOnly(t *testing.T) {
|
||||||
|
s, _ := agentStore(t)
|
||||||
|
key, err := s.Add(context.Background(), AddRequest{URL: "github:cursor/plugins", Agents: agents("comment-sicko")})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := map[string]string{"comment-sicko": "pstack/agents/comment-sicko.md"}
|
||||||
|
if got := lockedAgents(t, s, key); !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("agents = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
list, err := s.List()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(list) != 1 || !list[0].Agent || list[0].Name != "comment-sicko" {
|
||||||
|
t.Errorf("list = %+v, want just the agent", list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddAgentAliasThenAll(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, _ := agentStore(t)
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", Agents: agents("comment-sicko=sicko"), Skills: pick("tdd")}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := lockedAgents(t, s, "cursor/plugins"); got["sicko"] != "pstack/agents/comment-sicko.md" {
|
||||||
|
t.Errorf("agents = %v", got)
|
||||||
|
}
|
||||||
|
// Installing every agent replaces the list with "*".
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", AllAgents: true}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := lockedAgents(t, s, "cursor/plugins"); len(got) != 2 {
|
||||||
|
t.Errorf("agents = %v, want both", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddNothingListsAgents(t *testing.T) {
|
||||||
|
s, _ := agentStore(t)
|
||||||
|
_, err := s.Add(context.Background(), AddRequest{URL: "github:cursor/plugins"})
|
||||||
|
var sel *NoSelectionError
|
||||||
|
if !errors.As(err, &sel) || len(sel.AvailableAgents) != 2 {
|
||||||
|
t.Fatalf("err = %v, want a NoSelectionError listing both agents", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddUnknownAgent(t *testing.T) {
|
||||||
|
s, _ := agentStore(t)
|
||||||
|
_, err := s.Add(context.Background(), AddRequest{URL: "github:cursor/plugins", Agents: agents("nope")})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), `no agent "nope"`) {
|
||||||
|
t.Fatalf("err = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAgentModifiedUpstream(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, f := agentStore(t)
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", Agents: agents("comment-sicko", "poteto-agent")}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f.repos["github:cursor/plugins"].push("r2", withAgents(t, fixture(t, "tdd"), "comment-sicko:v2", "poteto-agent"))
|
||||||
|
sts := check(t, s)
|
||||||
|
if got, want := changes(sts[0]), []string{"↑comment-sicko"}; !reflect.DeepEqual(got, want) {
|
||||||
|
t.Fatalf("changes = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
ch := sts[0].Changes[0]
|
||||||
|
if !ch.Agent || ch.Label() != "agent comment-sicko" {
|
||||||
|
t.Errorf("change = %+v", ch)
|
||||||
|
}
|
||||||
|
d, err := Diff(ctx, ch)
|
||||||
|
if err != nil || !strings.Contains(d, "-v1") || !strings.Contains(d, "+v2") {
|
||||||
|
t.Errorf("diff = %q, err %v", d, err)
|
||||||
|
}
|
||||||
|
if err := s.Apply(sts); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := check(t, s); got[0].Outdated() {
|
||||||
|
t.Errorf("still outdated after apply: %v", changes(got[0]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAgentAddedUpstreamWithStar(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, f := agentStore(t)
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", AllAgents: true}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.repos["github:cursor/plugins"].push("r2", withAgents(t, fixture(t, "tdd"), "comment-sicko:v1", "poteto-agent", "new-one"))
|
||||||
|
sts := check(t, s)
|
||||||
|
if got, want := changes(sts[0]), []string{"+new-one"}; !reflect.DeepEqual(got, want) {
|
||||||
|
t.Fatalf("changes = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
// An added agent is a file, so the diff compares against an empty file.
|
||||||
|
d, err := Diff(ctx, sts[0].Changes[0])
|
||||||
|
if err != nil || !strings.Contains(d, "+name: new-one") {
|
||||||
|
t.Errorf("diff = %q, err %v", d, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAgentVanishesUpstream(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, f := agentStore(t)
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", Agents: agents("poteto-agent")}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.repos["github:cursor/plugins"].push("r2", withAgents(t, fixture(t, "tdd"), "comment-sicko"))
|
||||||
|
sts, err := s.Check(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if sts[0].Err == nil || !strings.Contains(sts[0].Err.Error(), `no agent "poteto-agent"`) {
|
||||||
|
t.Fatalf("status err = %v, want the missing agent reported", sts[0].Err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveAgent(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, _ := agentStore(t)
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", Agents: agents("comment-sicko", "poteto-agent")}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Remove("comment-sicko"); err == nil {
|
||||||
|
t.Error("Remove should only find skills")
|
||||||
|
}
|
||||||
|
if _, err := s.RemoveAgent("poteto-agent"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := lockedAgents(t, s, "cursor/plugins"); len(got) != 1 {
|
||||||
|
t.Errorf("agents = %v, want one left", got)
|
||||||
|
}
|
||||||
|
// The last entry takes the source with it.
|
||||||
|
if _, err := s.RemoveAgent("comment-sicko"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
m, err := manifest.Load(filepath.Join(s.Dir, ManifestFile))
|
||||||
|
if err != nil || len(m.Sources) != 0 {
|
||||||
|
t.Errorf("manifest = %+v, err %v; want the empty source dropped", m, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveSkillKeepsSourceWithAgents(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, _ := agentStore(t)
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", Skills: pick("tdd"), Agents: agents("comment-sicko")}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := s.Remove("tdd"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := lockedAgents(t, s, "cursor/plugins"); len(got) != 1 {
|
||||||
|
t.Errorf("agents = %v, want the agent kept", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAgentNameCollisionAcrossSources(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
s, f := agentStore(t)
|
||||||
|
f.repos["github:other/plugins"] = &fakeRepo{head: "r1", revs: map[string]string{"r1": withAgents(t, fixture(t, "x"), "comment-sicko")}}
|
||||||
|
if _, err := s.Add(ctx, AddRequest{URL: "github:cursor/plugins", Agents: agents("comment-sicko")}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err := s.Add(ctx, AddRequest{URL: "github:other/plugins", Agents: agents("comment-sicko")})
|
||||||
|
if err == nil || !strings.Contains(err.Error(), `agent "comment-sicko" comes from both`) {
|
||||||
|
t.Fatalf("err = %v, want an agent collision", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
+139
-67
@@ -3,6 +3,7 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
@@ -88,16 +89,24 @@ type AddRequest struct {
|
|||||||
// Skills to add. Ignored when All is set.
|
// Skills to add. Ignored when All is set.
|
||||||
Skills []manifest.Skill
|
Skills []manifest.Skill
|
||||||
All bool
|
All bool
|
||||||
|
// Agents to add, by name or path; ignored when AllAgents is set.
|
||||||
|
Agents []manifest.Skill
|
||||||
|
AllAgents bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoSelectionError is returned by Add when neither skills nor All were given.
|
// NoSelectionError is returned by Add when neither skills nor All were given.
|
||||||
type NoSelectionError struct {
|
type NoSelectionError struct {
|
||||||
Source string
|
Source string
|
||||||
Available []skills.Skill
|
Available []skills.Skill
|
||||||
|
AvailableAgents []skills.Skill
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NoSelectionError) Error() string {
|
func (e *NoSelectionError) Error() string {
|
||||||
return fmt.Sprintf("no skills selected from %s; available: %s", e.Source, available(e.Available))
|
msg := fmt.Sprintf("no skills selected from %s; available: %s", e.Source, available(e.Available))
|
||||||
|
if len(e.AvailableAgents) > 0 {
|
||||||
|
msg += "; agents: " + available(e.AvailableAgents)
|
||||||
|
}
|
||||||
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func available(found []skills.Skill) string {
|
func available(found []skills.Skill) string {
|
||||||
@@ -120,43 +129,60 @@ func (s Store) Add(ctx context.Context, req AddRequest) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
res, found, err := s.fetchSkills(ctx, ref)
|
res, found, agents, err := s.fetchSource(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("%s: %w", key, err)
|
return "", fmt.Errorf("%s: %w", key, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
if !req.All && len(req.Skills) == 0 && !req.AllAgents && len(req.Agents) == 0 {
|
||||||
case req.All:
|
return "", &NoSelectionError{Source: key, Available: found, AvailableAgents: agents}
|
||||||
src.Skills = manifest.Selection{All: true}
|
}
|
||||||
case len(req.Skills) == 0:
|
if err := selectInto(&src.Skills, req.Skills, req.All, found, key, "skill"); err != nil {
|
||||||
return "", &NoSelectionError{Source: key, Available: found}
|
return "", err
|
||||||
case src.Skills.All:
|
}
|
||||||
return "", fmt.Errorf("source %q already installs every skill", key)
|
if err := selectInto(&src.Agents, req.Agents, req.AllAgents, agents, key, "agent"); err != nil {
|
||||||
default:
|
return "", err
|
||||||
for _, k := range req.Skills {
|
|
||||||
if k.Name == "" {
|
|
||||||
i := slices.IndexFunc(found, func(f skills.Skill) bool { return f.Path == k.Path })
|
|
||||||
if i < 0 {
|
|
||||||
return "", fmt.Errorf("%s: no skill at %s", key, k.Path)
|
|
||||||
}
|
|
||||||
k.Name = found[i].Name
|
|
||||||
}
|
|
||||||
if slices.ContainsFunc(src.Skills.Items, func(e manifest.Skill) bool { return e.Installed() == k.Installed() }) {
|
|
||||||
return "", fmt.Errorf("%s is already installed from %s", k.Installed(), key)
|
|
||||||
}
|
|
||||||
src.Skills.Items = append(src.Skills.Items, k)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resolved, err := resolve(src.Skills, found)
|
resolved, err := resolve(src.Skills, found, "skill")
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("%s: %w", key, err)
|
||||||
|
}
|
||||||
|
resolvedAgents, err := resolve(src.Agents, agents, "agent")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("%s: %w", key, err)
|
return "", fmt.Errorf("%s: %w", key, err)
|
||||||
}
|
}
|
||||||
m.Sources[key] = src
|
m.Sources[key] = src
|
||||||
l.Sources[key] = &lock.Source{Locked: res.Locked, Skills: resolved}
|
l.Sources[key] = &lock.Source{Locked: res.Locked, Skills: resolved, Agents: resolvedAgents}
|
||||||
return key, s.save(m, l)
|
return key, s.save(m, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// selectInto adds the requested entries of one kind to sel, or switches it to "*".
|
||||||
|
func selectInto(sel *manifest.Selection, req []manifest.Skill, all bool, found []skills.Skill, key, kind string) error {
|
||||||
|
switch {
|
||||||
|
case all:
|
||||||
|
*sel = manifest.Selection{All: true}
|
||||||
|
case len(req) == 0:
|
||||||
|
case sel.All:
|
||||||
|
return fmt.Errorf("source %q already installs every %s", key, kind)
|
||||||
|
default:
|
||||||
|
for _, k := range req {
|
||||||
|
if k.Name == "" {
|
||||||
|
i := slices.IndexFunc(found, func(f skills.Skill) bool { return f.Path == k.Path })
|
||||||
|
if i < 0 {
|
||||||
|
return fmt.Errorf("%s: no %s at %s", key, kind, k.Path)
|
||||||
|
}
|
||||||
|
k.Name = found[i].Name
|
||||||
|
}
|
||||||
|
if slices.ContainsFunc(sel.Items, func(e manifest.Skill) bool { return e.Installed() == k.Installed() }) {
|
||||||
|
return fmt.Errorf("%s is already installed from %s", k.Installed(), key)
|
||||||
|
}
|
||||||
|
sel.Items = append(sel.Items, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// target resolves the source an add goes to and the flake ref to fetch: the pinned
|
// target resolves the source an add goes to and the flake ref to fetch: the pinned
|
||||||
// rev for a tracked source, the head of its ref for a new one. src is a copy that
|
// rev for a tracked source, the head of its ref for a new one. src is a copy that
|
||||||
// is safe to modify.
|
// is safe to modify.
|
||||||
@@ -180,10 +206,10 @@ func target(m *manifest.Manifest, l *lock.Lock, req AddRequest) (key string, src
|
|||||||
if locked == nil {
|
if locked == nil {
|
||||||
return "", nil, "", fmt.Errorf("source %q is in %s but not locked; run skm update %s first", key, ManifestFile, key)
|
return "", nil, "", fmt.Errorf("source %q is in %s but not locked; run skm update %s first", key, ManifestFile, key)
|
||||||
}
|
}
|
||||||
src = &manifest.Source{URL: existing.URL, Ref: existing.Ref, Skills: manifest.Selection{
|
src = &manifest.Source{URL: existing.URL, Ref: existing.Ref,
|
||||||
All: existing.Skills.All,
|
Skills: manifest.Selection{All: existing.Skills.All, Items: slices.Clone(existing.Skills.Items)},
|
||||||
Items: slices.Clone(existing.Skills.Items),
|
Agents: manifest.Selection{All: existing.Agents.All, Items: slices.Clone(existing.Agents.Items)},
|
||||||
}}
|
}
|
||||||
return key, src, fetch.AtRev(flakeRef(src), locked.Rev()), nil
|
return key, src, fetch.AtRev(flakeRef(src), locked.Rev()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +242,7 @@ func (s Store) Available(ctx context.Context, req AddRequest) ([]skills.Skill, m
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
_, found, err := s.fetchSkills(ctx, ref)
|
_, found, _, err := s.fetchSource(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("%s: %w", key, err)
|
return nil, nil, fmt.Errorf("%s: %w", key, err)
|
||||||
}
|
}
|
||||||
@@ -229,27 +255,41 @@ func (s Store) Available(ctx context.Context, req AddRequest) ([]skills.Skill, m
|
|||||||
return found, installed, nil
|
return found, installed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Store) fetchSkills(ctx context.Context, ref string) (fetch.Result, []skills.Skill, error) {
|
// fetchSource prefetches ref and finds its skills and agent definitions.
|
||||||
|
func (s Store) fetchSource(ctx context.Context, ref string) (fetch.Result, []skills.Skill, []skills.Skill, error) {
|
||||||
res, err := s.Fetcher.Prefetch(ctx, ref)
|
res, err := s.Fetcher.Prefetch(ctx, ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fetch.Result{}, nil, err
|
return fetch.Result{}, nil, nil, err
|
||||||
}
|
}
|
||||||
found, err := skills.Discover(res.StorePath)
|
found, err := skills.Discover(res.StorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fetch.Result{}, nil, err
|
return fetch.Result{}, nil, nil, err
|
||||||
}
|
}
|
||||||
if len(found) == 0 {
|
agents, err := skills.DiscoverAgents(res.StorePath)
|
||||||
return fetch.Result{}, nil, fmt.Errorf("%s contains no SKILL.md", ref)
|
if err != nil {
|
||||||
|
return fetch.Result{}, nil, nil, err
|
||||||
}
|
}
|
||||||
return res, found, nil
|
if len(found) == 0 && len(agents) == 0 {
|
||||||
|
return fetch.Result{}, nil, nil, fmt.Errorf("%s contains no SKILL.md or agent definition", ref)
|
||||||
|
}
|
||||||
|
return res, found, agents, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchSkills is fetchSource for callers that only install skills.
|
||||||
|
func (s Store) fetchSkills(ctx context.Context, ref string) (fetch.Result, []skills.Skill, error) {
|
||||||
|
res, found, _, err := s.fetchSource(ctx, ref)
|
||||||
|
if err == nil && len(found) == 0 {
|
||||||
|
err = fmt.Errorf("%s contains no SKILL.md", ref)
|
||||||
|
}
|
||||||
|
return res, found, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve maps installed names to paths within the source.
|
// resolve maps installed names to paths within the source.
|
||||||
func resolve(sel manifest.Selection, found []skills.Skill) (map[string]string, error) {
|
func resolve(sel manifest.Selection, found []skills.Skill, kind string) (map[string]string, error) {
|
||||||
out := map[string]string{}
|
out := map[string]string{}
|
||||||
add := func(name, path string) error {
|
add := func(name, path string) error {
|
||||||
if prev, dup := out[name]; dup {
|
if prev, dup := out[name]; dup {
|
||||||
return fmt.Errorf("two skills installed as %q: %s and %s", name, prev, path)
|
return fmt.Errorf("two %ss installed as %q: %s and %s", kind, name, prev, path)
|
||||||
}
|
}
|
||||||
out[name] = path
|
out[name] = path
|
||||||
return nil
|
return nil
|
||||||
@@ -258,7 +298,7 @@ func resolve(sel manifest.Selection, found []skills.Skill) (map[string]string, e
|
|||||||
if sel.All {
|
if sel.All {
|
||||||
for _, f := range found {
|
for _, f := range found {
|
||||||
if err := add(f.Name, f.Path); err != nil {
|
if err := add(f.Name, f.Path); err != nil {
|
||||||
return nil, fmt.Errorf(`%w; list skills explicitly, picking one with "path"`, err)
|
return nil, fmt.Errorf(`%w; list %ss explicitly, picking one with "path"`, err, kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
@@ -272,15 +312,15 @@ func resolve(sel manifest.Selection, found []skills.Skill) (map[string]string, e
|
|||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case len(matches) == 0 && k.Path != "":
|
case len(matches) == 0 && k.Path != "":
|
||||||
return nil, fmt.Errorf("no skill %q at %s", k.Name, k.Path)
|
return nil, fmt.Errorf("no %s %q at %s", kind, k.Name, k.Path)
|
||||||
case len(matches) == 0:
|
case len(matches) == 0:
|
||||||
return nil, fmt.Errorf("no skill %q; available: %s", k.Name, available(found))
|
return nil, fmt.Errorf("no %s %q; available: %s", kind, k.Name, available(found))
|
||||||
case len(matches) > 1:
|
case len(matches) > 1:
|
||||||
var paths []string
|
var paths []string
|
||||||
for _, f := range matches {
|
for _, f := range matches {
|
||||||
paths = append(paths, f.Path)
|
paths = append(paths, f.Path)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf(`several skills named %q (%s); pick one with "path"`, k.Name, strings.Join(paths, ", "))
|
return nil, fmt.Errorf(`several %ss named %q (%s); pick one with "path"`, kind, k.Name, strings.Join(paths, ", "))
|
||||||
}
|
}
|
||||||
if err := add(k.Installed(), matches[0].Path); err != nil {
|
if err := add(k.Installed(), matches[0].Path); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -290,13 +330,19 @@ func resolve(sel manifest.Selection, found []skills.Skill) (map[string]string, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkCollisions(l *lock.Lock) error {
|
func checkCollisions(l *lock.Lock) error {
|
||||||
owner := map[string]string{}
|
for _, kind := range []string{"skill", "agent"} {
|
||||||
for _, key := range slices.Sorted(maps.Keys(l.Sources)) {
|
owner := map[string]string{}
|
||||||
for _, name := range slices.Sorted(maps.Keys(l.Sources[key].Skills)) {
|
for _, key := range slices.Sorted(maps.Keys(l.Sources)) {
|
||||||
if prev, ok := owner[name]; ok {
|
installed := l.Sources[key].Skills
|
||||||
return fmt.Errorf(`skill %q comes from both %s and %s; rename one with "as"`, name, prev, key)
|
if kind == "agent" {
|
||||||
|
installed = l.Sources[key].Agents
|
||||||
|
}
|
||||||
|
for _, name := range slices.Sorted(maps.Keys(installed)) {
|
||||||
|
if prev, ok := owner[name]; ok {
|
||||||
|
return fmt.Errorf(`%s %q comes from both %s and %s; rename one with "as"`, kind, name, prev, key)
|
||||||
|
}
|
||||||
|
owner[name] = key
|
||||||
}
|
}
|
||||||
owner[name] = key
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -304,42 +350,51 @@ func checkCollisions(l *lock.Lock) error {
|
|||||||
|
|
||||||
// Remove drops one installed skill, and its source once that is empty.
|
// Remove drops one installed skill, and its source once that is empty.
|
||||||
// Returns the source it came from.
|
// Returns the source it came from.
|
||||||
func (s Store) Remove(name string) (string, error) {
|
func (s Store) Remove(name string) (string, error) { return s.removeOne(name, false) }
|
||||||
|
|
||||||
|
// RemoveAgent drops one installed agent definition, like Remove.
|
||||||
|
func (s Store) RemoveAgent(name string) (string, error) { return s.removeOne(name, true) }
|
||||||
|
|
||||||
|
func (s Store) removeOne(name string, agent bool) (string, error) {
|
||||||
|
kind := "skill"
|
||||||
|
if agent {
|
||||||
|
kind = "agent"
|
||||||
|
}
|
||||||
m, l, err := s.load()
|
m, l, err := s.load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
for _, key := range slices.Sorted(maps.Keys(m.Sources)) {
|
for _, key := range slices.Sorted(maps.Keys(m.Sources)) {
|
||||||
src := m.Sources[key]
|
src := m.Sources[key]
|
||||||
i := slices.IndexFunc(src.Skills.Items, func(k manifest.Skill) bool { return k.Installed() == name })
|
sel, locks := &src.Skills, func(ls *lock.Source) map[string]string { return ls.Skills }
|
||||||
locked := isLocked(l, key, name)
|
if agent {
|
||||||
|
sel, locks = &src.Agents, func(ls *lock.Source) map[string]string { return ls.Agents }
|
||||||
|
}
|
||||||
|
i := slices.IndexFunc(sel.Items, func(k manifest.Skill) bool { return k.Installed() == name })
|
||||||
|
locked := l.Sources[key] != nil && has(locks(l.Sources[key]), name)
|
||||||
if i < 0 && !locked {
|
if i < 0 && !locked {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if src.Skills.All {
|
if sel.All {
|
||||||
return "", fmt.Errorf(`%s comes from %s, which installs every skill ("*"); remove the whole source with --source %s`, name, key, key)
|
return "", fmt.Errorf(`%s comes from %s, which installs every %s ("*"); remove the whole source with --source %s`, name, key, kind, key)
|
||||||
}
|
}
|
||||||
if i >= 0 {
|
if i >= 0 {
|
||||||
src.Skills.Items = slices.Delete(src.Skills.Items, i, i+1)
|
sel.Items = slices.Delete(sel.Items, i, i+1)
|
||||||
}
|
}
|
||||||
if locked {
|
if locked {
|
||||||
delete(l.Sources[key].Skills, name)
|
delete(locks(l.Sources[key]), name)
|
||||||
}
|
}
|
||||||
if len(src.Skills.Items) == 0 {
|
if src.Empty() {
|
||||||
delete(m.Sources, key)
|
delete(m.Sources, key)
|
||||||
delete(l.Sources, key)
|
delete(l.Sources, key)
|
||||||
}
|
}
|
||||||
return key, s.save(m, l)
|
return key, s.save(m, l)
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("no installed skill %q", name)
|
return "", fmt.Errorf("no installed %s %q", kind, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isLocked(l *lock.Lock, key, name string) bool {
|
func has(m map[string]string, name string) bool {
|
||||||
src := l.Sources[key]
|
_, ok := m[name]
|
||||||
if src == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
_, ok := src.Skills[name]
|
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,9 +417,11 @@ type Installed struct {
|
|||||||
Source string
|
Source string
|
||||||
Path string
|
Path string
|
||||||
Rev string
|
Rev string
|
||||||
|
// Agent is set for an agent definition, which Path names as a file.
|
||||||
|
Agent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// List returns the locked skills, sorted by name.
|
// List returns the locked skills and agents, sorted by name.
|
||||||
func (s Store) List() ([]Installed, error) {
|
func (s Store) List() ([]Installed, error) {
|
||||||
_, l, err := s.load()
|
_, l, err := s.load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -375,7 +432,22 @@ func (s Store) List() ([]Installed, error) {
|
|||||||
for name, path := range src.Skills {
|
for name, path := range src.Skills {
|
||||||
out = append(out, Installed{Name: name, Source: key, Path: path, Rev: src.Rev()})
|
out = append(out, Installed{Name: name, Source: key, Path: path, Rev: src.Rev()})
|
||||||
}
|
}
|
||||||
|
for name, path := range src.Agents {
|
||||||
|
out = append(out, Installed{Name: name, Source: key, Path: path, Rev: src.Rev(), Agent: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
slices.SortFunc(out, func(a, b Installed) int { return strings.Compare(a.Name, b.Name) })
|
slices.SortFunc(out, func(a, b Installed) int {
|
||||||
|
return cmp.Or(strings.Compare(a.Name, b.Name), compareBool(a.Agent, b.Agent))
|
||||||
|
})
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func compareBool(a, b bool) int {
|
||||||
|
switch {
|
||||||
|
case a == b:
|
||||||
|
return 0
|
||||||
|
case b:
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
@@ -140,7 +140,7 @@ func (s Store) Import(ctx context.Context, vercelPath, localDir string) (ImportR
|
|||||||
if !f.src.Skills.All && len(f.src.Skills.Items) == 0 {
|
if !f.src.Skills.All && len(f.src.Skills.Items) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
resolved, err := resolve(f.src.Skills, f.found)
|
resolved, err := resolve(f.src.Skills, f.found, "skill")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rep, fmt.Errorf("%s: %w", f.key, err)
|
return rep, fmt.Errorf("%s: %w", f.key, err)
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-21
@@ -31,15 +31,25 @@ func (k ChangeKind) Symbol() string {
|
|||||||
return [...]string{"↑", "+", "-"}[k]
|
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 {
|
type Change struct {
|
||||||
Name string
|
Name string
|
||||||
Kind ChangeKind
|
Kind ChangeKind
|
||||||
// Skill directories in the store; empty when added or removed, and Old is
|
// Agent is set for an agent definition, whose Old and New are files, not directories.
|
||||||
// also empty for a source dropped from the manifest.
|
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
|
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.
|
// SourceStatus compares a source's lock entry with the head of its ref.
|
||||||
type SourceStatus struct {
|
type SourceStatus struct {
|
||||||
Source string
|
Source string
|
||||||
@@ -91,7 +101,7 @@ func selectSources(m *manifest.Manifest, l *lock.Lock, names []string) ([]string
|
|||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
key, ok := owner(m, l, name)
|
key, ok := owner(m, l, name)
|
||||||
if !ok {
|
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
|
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 {
|
if _, ok := src.Skills[name]; ok {
|
||||||
return key, true
|
return key, true
|
||||||
}
|
}
|
||||||
|
if _, ok := src.Agents[name]; ok {
|
||||||
|
return key, true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for key, src := range m.Sources {
|
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
|
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)) {
|
for _, name := range slices.Sorted(maps.Keys(locked.Skills)) {
|
||||||
st.Changes = append(st.Changes, Change{Name: name, Kind: Removed})
|
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
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,31 +167,60 @@ func (s Store) check(ctx context.Context, key string, src *manifest.Source, lock
|
|||||||
}
|
}
|
||||||
st.NewRev = res.Rev()
|
st.NewRev = res.Rev()
|
||||||
found, err := skills.Discover(res.StorePath)
|
found, err := skills.Discover(res.StorePath)
|
||||||
|
var agents []skills.Skill
|
||||||
|
if err == nil {
|
||||||
|
agents, err = skills.DiscoverAgents(res.StorePath)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
st.next = &lock.Source{Locked: res.Locked}
|
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 {
|
if err != nil {
|
||||||
st.Err = err
|
st.Err = err
|
||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
names := slices.Sorted(maps.Keys(locked.Skills))
|
for _, kind := range []struct {
|
||||||
for name := range st.next.Skills {
|
old, new map[string]string
|
||||||
if _, ok := locked.Skills[name]; !ok {
|
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)
|
names = append(names, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slices.Sort(names)
|
slices.Sort(names)
|
||||||
|
|
||||||
|
var out []Change
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
oldPath, wasLocked := locked.Skills[name]
|
oldPath, wasLocked := locked[name]
|
||||||
newPath, stays := st.next.Skills[name]
|
newPath, stays := next[name]
|
||||||
ch := Change{Name: name}
|
ch := Change{Name: name, Agent: agent}
|
||||||
if wasLocked {
|
if wasLocked {
|
||||||
ch.Old = filepath.Join(oldRoot, oldPath)
|
ch.Old = filepath.Join(oldRoot, oldPath)
|
||||||
}
|
}
|
||||||
if stays {
|
if stays {
|
||||||
ch.New = filepath.Join(res.StorePath, newPath)
|
ch.New = filepath.Join(newRoot, newPath)
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case !stays:
|
case !stays:
|
||||||
@@ -184,17 +230,16 @@ func (s Store) check(ctx context.Context, key string, src *manifest.Source, lock
|
|||||||
default:
|
default:
|
||||||
same, err := sameDir(ctx, ch.Old, ch.New)
|
same, err := sameDir(ctx, ch.Old, ch.New)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
st.Err = err
|
return nil, err
|
||||||
return st
|
|
||||||
}
|
}
|
||||||
if same {
|
if same {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ch.Kind = Modified
|
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.
|
// 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))
|
heads = append(heads, fmt.Sprintf("update %s %.7s→%.7s", st.Source, st.OldRev, st.NewRev))
|
||||||
}
|
}
|
||||||
for _, ch := range st.Changes {
|
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")
|
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.
|
// Diff renders a change as a unified diff with a/<name> and b/<name> paths.
|
||||||
func Diff(ctx context.Context, ch Change) (string, error) {
|
func Diff(ctx context.Context, ch Change) (string, error) {
|
||||||
empty, err := os.MkdirTemp("", "skm-empty-")
|
// An added or removed agent is a file, so it needs an empty file to compare with.
|
||||||
if err != nil {
|
var empty string
|
||||||
return "", err
|
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)
|
defer os.Remove(empty)
|
||||||
oldDir, newDir := cmp.Or(ch.Old, empty), cmp.Or(ch.New, empty)
|
oldDir, newDir := cmp.Or(ch.Old, empty), cmp.Or(ch.New, empty)
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ type Source struct {
|
|||||||
Locked map[string]any `json:"locked"`
|
Locked map[string]any `json:"locked"`
|
||||||
// Skills maps installed name to the skill's directory in the source.
|
// Skills maps installed name to the skill's directory in the source.
|
||||||
Skills map[string]string `json:"skills"`
|
Skills map[string]string `json:"skills"`
|
||||||
|
// Agents maps installed name to the agent's .md file in the source.
|
||||||
|
Agents map[string]string `json:"agents,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Source) Rev() string {
|
func (s Source) Rev() string {
|
||||||
|
|||||||
@@ -18,9 +18,16 @@ type Source struct {
|
|||||||
// Ref is the branch or tag to track; empty means the default branch.
|
// Ref is the branch or tag to track; empty means the default branch.
|
||||||
Ref string `json:"ref,omitempty"`
|
Ref string `json:"ref,omitempty"`
|
||||||
Skills Selection `json:"skills"`
|
Skills Selection `json:"skills"`
|
||||||
|
// Agents are subagent definitions (agents/<name>.md files). Path, when set, is the file.
|
||||||
|
Agents Selection `json:"agents,omitzero"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selection is either "*" (every skill in the repo) or a list of skills.
|
// 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 {
|
type Selection struct {
|
||||||
All bool
|
All bool
|
||||||
Items []Skill
|
Items []Skill
|
||||||
|
|||||||
@@ -39,6 +39,32 @@ func TestSelectionJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSourceAgentsOmittedWhenEmpty(t *testing.T) {
|
||||||
|
// A manifest without agents must stay byte-identical when skm rewrites it.
|
||||||
|
skillsOnly := `{"url":"github:mp/skills","skills":["tdd"]}`
|
||||||
|
var src Source
|
||||||
|
if err := json.Unmarshal([]byte(skillsOnly), &src); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
out, err := json.Marshal(src)
|
||||||
|
if err != nil || string(out) != skillsOnly {
|
||||||
|
t.Errorf("marshal = %s, err %v; want %s", out, err, skillsOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
withAgents := `{"url":"github:cursor/plugins","skills":[],"agents":["comment-sicko",{"name":"poteto","as":"p"}]}`
|
||||||
|
if err := json.Unmarshal([]byte(withAgents), &src); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := src.Agents.Items; len(got) != 2 || got[0].Name != "comment-sicko" || got[1].Installed() != "p" {
|
||||||
|
t.Errorf("agents = %+v", got)
|
||||||
|
}
|
||||||
|
src.Skills = Selection{}
|
||||||
|
out, err = json.Marshal(src)
|
||||||
|
if err != nil || string(out) != withAgents {
|
||||||
|
t.Errorf("marshal = %s, err %v; want %s", out, err, withAgents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSelectionRejectsOtherStrings(t *testing.T) {
|
func TestSelectionRejectsOtherStrings(t *testing.T) {
|
||||||
var s Selection
|
var s Selection
|
||||||
if err := json.Unmarshal([]byte(`"tdd"`), &s); err == nil {
|
if err := json.Unmarshal([]byte(`"tdd"`), &s); err == nil {
|
||||||
|
|||||||
@@ -59,6 +59,42 @@ func Discover(root string) ([]Skill, error) {
|
|||||||
return found, err
|
return found, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiscoverAgents returns every agent definition under root in lexical walk order: a
|
||||||
|
// .md file directly inside a directory named "agents" whose frontmatter has a name.
|
||||||
|
// Path is the file, slash-separated and relative to root. Files without a name
|
||||||
|
// (an agents/README.md) are not agents.
|
||||||
|
func DiscoverAgents(root string) ([]Skill, error) {
|
||||||
|
var found []Skill
|
||||||
|
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if d.IsDir() {
|
||||||
|
if d.Name() == ".git" {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if filepath.Base(filepath.Dir(path)) != "agents" || filepath.Ext(path) != ".md" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
name, err := frontmatterName(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if name == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
rel, err := filepath.Rel(root, path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
found = append(found, Skill{Name: name, Path: filepath.ToSlash(rel)})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return found, err
|
||||||
|
}
|
||||||
|
|
||||||
// frontmatterName reads `name:` from the YAML frontmatter, or "" if absent.
|
// frontmatterName reads `name:` from the YAML frontmatter, or "" if absent.
|
||||||
func frontmatterName(path string) (string, error) {
|
func frontmatterName(path string) (string, error) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
|
|||||||
@@ -37,6 +37,30 @@ func TestDiscover(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDiscoverAgents(t *testing.T) {
|
||||||
|
root := t.TempDir()
|
||||||
|
write(t, root, "pstack/agents/comment-sicko.md", "---\nname: comment-sicko\ndescription: x\n---\nbody\n")
|
||||||
|
write(t, root, "harness/claude-code/agents/comment-sicko.md", "---\nname: comment-sicko\n---\n")
|
||||||
|
// Not agents: no frontmatter name, wrong directory, nested deeper, not markdown, .git.
|
||||||
|
write(t, root, "pstack/agents/README.md", "# agents\n")
|
||||||
|
write(t, root, "pstack/docs/other.md", "---\nname: other\n---\n")
|
||||||
|
write(t, root, "pstack/agents/sub/inner.md", "---\nname: inner\n---\n")
|
||||||
|
write(t, root, "pstack/agents/notes.txt", "name: notes\n")
|
||||||
|
write(t, root, ".git/agents/hidden.md", "---\nname: hidden\n---\n")
|
||||||
|
|
||||||
|
got, err := DiscoverAgents(root)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := []Skill{
|
||||||
|
{Name: "comment-sicko", Path: "harness/claude-code/agents/comment-sicko.md"},
|
||||||
|
{Name: "comment-sicko", Path: "pstack/agents/comment-sicko.md"},
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, want) {
|
||||||
|
t.Errorf("got %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDiscoverRootSkill(t *testing.T) {
|
func TestDiscoverRootSkill(t *testing.T) {
|
||||||
root := t.TempDir()
|
root := t.TempDir()
|
||||||
write(t, root, "SKILL.md", "---\nname: ponytail\n---\n")
|
write(t, root, "SKILL.md", "---\nname: ponytail\n---\n")
|
||||||
|
|||||||
@@ -25,8 +25,11 @@ const (
|
|||||||
modeSub
|
modeSub
|
||||||
)
|
)
|
||||||
|
|
||||||
// row is a source header (skill == "") or one of its installed skills.
|
// row is a source header (skill == "") or one of its installed skills or agents.
|
||||||
type row struct{ source, skill, path string }
|
type row struct {
|
||||||
|
source, skill, path string
|
||||||
|
agent bool
|
||||||
|
}
|
||||||
|
|
||||||
type statusMsg struct {
|
type statusMsg struct {
|
||||||
source string
|
source string
|
||||||
@@ -110,7 +113,7 @@ func (d *dashboard) reload() error {
|
|||||||
for _, src := range slices.Sorted(maps.Keys(bySource)) {
|
for _, src := range slices.Sorted(maps.Keys(bySource)) {
|
||||||
d.rows = append(d.rows, row{source: src})
|
d.rows = append(d.rows, row{source: src})
|
||||||
for _, i := range bySource[src] {
|
for _, i := range bySource[src] {
|
||||||
d.rows = append(d.rows, row{source: src, skill: i.Name, path: i.Path})
|
d.rows = append(d.rows, row{source: src, skill: i.Name, path: i.Path, agent: i.Agent})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for src := range d.status {
|
for src := range d.status {
|
||||||
@@ -281,7 +284,7 @@ func (d *dashboard) key(msg tea.KeyPressMsg) tea.Cmd {
|
|||||||
d.review([]core.SourceStatus{d.status[r.source]})
|
d.review([]core.SourceStatus{d.status[r.source]})
|
||||||
case "d":
|
case "d":
|
||||||
if r.skill != "" {
|
if r.skill != "" {
|
||||||
d.ask(fmt.Sprintf("remove %s from %s?", r.skill, r.source), func() tea.Cmd { return d.remove(r.skill) })
|
d.ask(fmt.Sprintf("remove %s from %s?", r.skill, r.source), func() tea.Cmd { return d.remove(r.skill, r.agent) })
|
||||||
} else {
|
} else {
|
||||||
d.ask(fmt.Sprintf("remove source %s and all its skills?", r.source), func() tea.Cmd { return d.removeSource(r.source) })
|
d.ask(fmt.Sprintf("remove source %s and all its skills?", r.source), func() tea.Cmd { return d.removeSource(r.source) })
|
||||||
}
|
}
|
||||||
@@ -325,10 +328,14 @@ func (d *dashboard) add(url string, found, chosen []skills.Skill) tea.Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dashboard) remove(skill string) tea.Cmd {
|
func (d *dashboard) remove(skill string, agent bool) tea.Cmd {
|
||||||
store := d.store
|
store := d.store
|
||||||
return func() tea.Msg {
|
return func() tea.Msg {
|
||||||
key, err := store.Remove(skill)
|
rm := store.Remove
|
||||||
|
if agent {
|
||||||
|
rm = store.RemoveAgent
|
||||||
|
}
|
||||||
|
key, err := rm(skill)
|
||||||
return doneMsg{fmt.Sprintf("removed %s from %s", skill, key), []string{key}, err}
|
return doneMsg{fmt.Sprintf("removed %s from %s", skill, key), []string{key}, err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,11 +374,15 @@ func (d *dashboard) render() string {
|
|||||||
}
|
}
|
||||||
mark := " "
|
mark := " "
|
||||||
for _, ch := range st.Changes {
|
for _, ch := range st.Changes {
|
||||||
if ch.Name == r.skill {
|
if ch.Name == r.skill && ch.Agent == r.agent {
|
||||||
mark = symbol(ch.Kind)
|
mark = symbol(ch.Kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(&b, "%s %s %s %s\n", cursor, mark, r.skill, dim.Render(r.path))
|
name := r.skill
|
||||||
|
if r.agent {
|
||||||
|
name += " " + dim.Render("(agent)")
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&b, "%s %s %s %s\n", cursor, mark, name, dim.Render(r.path))
|
||||||
}
|
}
|
||||||
if len(d.rows) == 0 {
|
if len(d.rows) == 0 {
|
||||||
b.WriteString(dim.Render(" no skills yet; press a to add a source") + "\n")
|
b.WriteString(dim.Render(" no skills yet; press a to add a source") + "\n")
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ func (r *review) view() string {
|
|||||||
|
|
||||||
var left strings.Builder
|
var left strings.Builder
|
||||||
for j, ch := range st.Changes {
|
for j, ch := range st.Changes {
|
||||||
line := symbol(ch.Kind) + " " + ch.Name
|
line := symbol(ch.Kind) + " " + ch.Label()
|
||||||
if j == r.sel {
|
if j == r.sel {
|
||||||
line = selected.Render("› ") + line
|
line = selected.Render("› ") + line
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+22
-1
@@ -9,6 +9,8 @@ let
|
|||||||
cfg = config.programs.skill-manager;
|
cfg = config.programs.skill-manager;
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
|
|
||||||
|
sources = (lib.importJSON cfg.lockFile).sources;
|
||||||
|
|
||||||
# installed name -> store path of the skill directory
|
# installed name -> store path of the skill directory
|
||||||
skills = lib.concatMapAttrs (
|
skills = lib.concatMapAttrs (
|
||||||
_: src:
|
_: src:
|
||||||
@@ -16,7 +18,16 @@ let
|
|||||||
tree = builtins.fetchTree src.locked;
|
tree = builtins.fetchTree src.locked;
|
||||||
in
|
in
|
||||||
lib.mapAttrs (_: path: if path == "." then "${tree}" else "${tree}/${path}") src.skills
|
lib.mapAttrs (_: path: if path == "." then "${tree}" else "${tree}/${path}") src.skills
|
||||||
) (lib.importJSON cfg.lockFile).sources;
|
) sources;
|
||||||
|
|
||||||
|
# installed name -> store path of the agent definition (a .md file)
|
||||||
|
agents = lib.concatMapAttrs (
|
||||||
|
_: src:
|
||||||
|
let
|
||||||
|
tree = builtins.fetchTree src.locked;
|
||||||
|
in
|
||||||
|
lib.mapAttrs (_: path: "${tree}/${path}") (src.agents or { })
|
||||||
|
) sources;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.programs.skill-manager = {
|
options.programs.skill-manager = {
|
||||||
@@ -52,6 +63,12 @@ in
|
|||||||
description = "Directories, relative to home, that get one symlink per skill.";
|
description = "Directories, relative to home, that get one symlink per skill.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
agentTargets = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ ".claude/agents" ];
|
||||||
|
description = "Directories, relative to home, that get one <name>.md symlink per agent definition.";
|
||||||
|
};
|
||||||
|
|
||||||
switchCommand = mkOption {
|
switchCommand = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "";
|
default = "";
|
||||||
@@ -71,6 +88,10 @@ in
|
|||||||
lib.concatMap (
|
lib.concatMap (
|
||||||
target: lib.mapAttrsToList (name: source: lib.nameValuePair "${target}/${name}" { inherit source; }) skills
|
target: lib.mapAttrsToList (name: source: lib.nameValuePair "${target}/${name}" { inherit source; }) skills
|
||||||
) cfg.targets
|
) cfg.targets
|
||||||
|
++ lib.concatMap (
|
||||||
|
target:
|
||||||
|
lib.mapAttrsToList (name: source: lib.nameValuePair "${target}/${name}.md" { inherit source; }) agents
|
||||||
|
) cfg.agentTargets
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user