feat: offer agents in the add picker and dashboard
The interactive add lists a source's agents next to its skills, tagged `agent`; Pick and Store.Available return both. Same-named agents get their file path in the manifest, like skills. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
df8d11d8cb
commit
1402e0ee07
6 files changed
+198
-59
No files matched your search
+12
-9
@@ -231,28 +231,31 @@ func Select(found, chosen []skills.Skill) []manifest.Skill {
|
||||
return out
|
||||
}
|
||||
|
||||
// Available lists the skills Add would choose from, and which of their paths are
|
||||
// already installed from that source.
|
||||
func (s Store) Available(ctx context.Context, req AddRequest) ([]skills.Skill, map[string]bool, error) {
|
||||
// Available lists the skills and agents Add would choose from, and which of their
|
||||
// paths are already installed from that source.
|
||||
func (s Store) Available(ctx context.Context, req AddRequest) (found, agents []skills.Skill, installed map[string]bool, err error) {
|
||||
m, l, err := s.load()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
key, _, ref, err := target(m, l, req)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
_, found, _, err := s.fetchSource(ctx, ref)
|
||||
_, found, agents, err = s.fetchSource(ctx, ref)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("%s: %w", key, err)
|
||||
return nil, nil, nil, fmt.Errorf("%s: %w", key, err)
|
||||
}
|
||||
installed := map[string]bool{}
|
||||
installed = map[string]bool{}
|
||||
if locked := l.Sources[key]; locked != nil {
|
||||
for _, path := range locked.Skills {
|
||||
installed[path] = true
|
||||
}
|
||||
for _, path := range locked.Agents {
|
||||
installed[path] = true
|
||||
}
|
||||
}
|
||||
return found, installed, nil
|
||||
return found, agents, installed, nil
|
||||
}
|
||||
|
||||
// fetchSource prefetches ref and finds its skills and agent definitions.
|
||||
|
||||
@@ -39,6 +39,7 @@ type statusMsg struct {
|
||||
type availableMsg struct {
|
||||
url string
|
||||
found []skills.Skill
|
||||
agents []skills.Skill
|
||||
installed map[string]bool
|
||||
err error
|
||||
}
|
||||
@@ -173,12 +174,12 @@ func (d *dashboard) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return d, nil
|
||||
}
|
||||
d.note = ""
|
||||
d.open(newPicker("add from "+msg.url, msg.found, msg.installed), func(c component) tea.Cmd {
|
||||
d.open(newPicker("add from "+msg.url, msg.found, msg.agents, msg.installed), func(c component) tea.Cmd {
|
||||
p := c.(*picker)
|
||||
if p.canceled {
|
||||
return nil
|
||||
}
|
||||
return d.add(msg.url, p.items, p.selection())
|
||||
return d.add(msg.url, p)
|
||||
})
|
||||
case doneMsg:
|
||||
d.mode = modeList
|
||||
@@ -238,8 +239,8 @@ func (d *dashboard) key(msg tea.KeyPressMsg) tea.Cmd {
|
||||
d.mode, d.note = modeBusy, "fetching "+url
|
||||
ctx, store := d.ctx, d.store
|
||||
return func() tea.Msg {
|
||||
found, installed, err := store.Available(ctx, core.AddRequest{URL: url})
|
||||
return availableMsg{url, found, installed, err}
|
||||
found, agents, installed, err := store.Available(ctx, core.AddRequest{URL: url})
|
||||
return availableMsg{url, found, agents, installed, err}
|
||||
}
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
@@ -315,12 +316,20 @@ func (d *dashboard) review(statuses []core.SourceStatus) {
|
||||
})
|
||||
}
|
||||
|
||||
func (d *dashboard) add(url string, found, chosen []skills.Skill) tea.Cmd {
|
||||
req := core.AddRequest{URL: url, Skills: core.Select(found, chosen)}
|
||||
func (d *dashboard) add(url string, p *picker) tea.Cmd {
|
||||
chosenSkills, chosenAgents := p.selection()
|
||||
req := core.AddRequest{
|
||||
URL: url,
|
||||
Skills: core.Select(p.skillItems, chosenSkills),
|
||||
Agents: core.Select(p.agentItems, chosenAgents),
|
||||
}
|
||||
var names []string
|
||||
for _, c := range chosen {
|
||||
for _, c := range chosenSkills {
|
||||
names = append(names, c.Name)
|
||||
}
|
||||
for _, c := range chosenAgents {
|
||||
names = append(names, c.Name+" (agent)")
|
||||
}
|
||||
ctx, store := d.ctx, d.store
|
||||
return func() tea.Msg {
|
||||
key, err := store.Add(ctx, req)
|
||||
|
||||
+66
-32
@@ -10,35 +10,51 @@ import (
|
||||
"skill-manager/internal/skills"
|
||||
)
|
||||
|
||||
// picker is a filterable multi-select over a source's skills. Typing filters;
|
||||
// already-installed skills are shown but can't be picked.
|
||||
// entry is one row of the picker: a skill or an agent definition.
|
||||
type entry struct {
|
||||
skills.Skill
|
||||
agent bool
|
||||
}
|
||||
|
||||
// picker is a filterable multi-select over a source's skills and agents. Typing
|
||||
// filters; already-installed entries are shown but can't be picked.
|
||||
type picker struct {
|
||||
title string
|
||||
items []skills.Skill
|
||||
installed map[string]bool // by path
|
||||
filter string
|
||||
cursor int // index into visible()
|
||||
picked map[int]bool
|
||||
width int
|
||||
height int
|
||||
done bool
|
||||
canceled bool
|
||||
title string
|
||||
// skillItems and agentItems are what the source offers; items is both, skills first.
|
||||
skillItems, agentItems []skills.Skill
|
||||
items []entry
|
||||
installed map[string]bool // by path
|
||||
filter string
|
||||
cursor int // index into visible()
|
||||
picked map[int]bool
|
||||
width int
|
||||
height int
|
||||
done bool
|
||||
canceled bool
|
||||
}
|
||||
|
||||
func newPicker(title string, items []skills.Skill, installed map[string]bool) *picker {
|
||||
return &picker{title: title, items: items, installed: installed, picked: map[int]bool{}}
|
||||
func newPicker(title string, skillItems, agentItems []skills.Skill, installed map[string]bool) *picker {
|
||||
p := &picker{title: title, skillItems: skillItems, agentItems: agentItems, installed: installed, picked: map[int]bool{}}
|
||||
for _, s := range skillItems {
|
||||
p.items = append(p.items, entry{Skill: s})
|
||||
}
|
||||
for _, a := range agentItems {
|
||||
p.items = append(p.items, entry{Skill: a, agent: true})
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// Pick lets the user choose skills from items. It returns ErrCanceled on escape.
|
||||
func Pick(ctx context.Context, title string, items []skills.Skill, installed map[string]bool) ([]skills.Skill, error) {
|
||||
p := newPicker(title, items, installed)
|
||||
// Pick lets the user choose skills and agents. It returns ErrCanceled on escape.
|
||||
func Pick(ctx context.Context, title string, skillItems, agentItems []skills.Skill, installed map[string]bool) (chosenSkills, chosenAgents []skills.Skill, err error) {
|
||||
p := newPicker(title, skillItems, agentItems, installed)
|
||||
if err := run(ctx, p); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if p.canceled {
|
||||
return nil, ErrCanceled
|
||||
return nil, nil, ErrCanceled
|
||||
}
|
||||
return p.selection(), nil
|
||||
chosenSkills, chosenAgents = p.selection()
|
||||
return chosenSkills, chosenAgents, nil
|
||||
}
|
||||
|
||||
func (p *picker) visible() []int {
|
||||
@@ -52,14 +68,28 @@ func (p *picker) visible() []int {
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *picker) selection() []skills.Skill {
|
||||
var out []skills.Skill
|
||||
for i, s := range p.items {
|
||||
if p.picked[i] {
|
||||
out = append(out, s)
|
||||
// selection splits the picked entries into skills and agents.
|
||||
func (p *picker) selection() (chosenSkills, chosenAgents []skills.Skill) {
|
||||
for i, e := range p.items {
|
||||
switch {
|
||||
case !p.picked[i]:
|
||||
case e.agent:
|
||||
chosenAgents = append(chosenAgents, e.Skill)
|
||||
default:
|
||||
chosenSkills = append(chosenSkills, e.Skill)
|
||||
}
|
||||
}
|
||||
return out
|
||||
return chosenSkills, chosenAgents
|
||||
}
|
||||
|
||||
func (p *picker) count() int {
|
||||
n := 0
|
||||
for _, on := range p.picked {
|
||||
if on {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (p *picker) toggle(i int) {
|
||||
@@ -78,11 +108,11 @@ func (p *picker) update(msg tea.Msg) tea.Cmd {
|
||||
case "ctrl+c", "esc":
|
||||
p.canceled, p.done = true, true
|
||||
case "enter":
|
||||
// Enter with nothing picked takes the highlighted skill.
|
||||
if len(p.selection()) == 0 && p.cursor < len(vis) {
|
||||
// Enter with nothing picked takes the highlighted entry.
|
||||
if p.count() == 0 && p.cursor < len(vis) {
|
||||
p.toggle(vis[p.cursor])
|
||||
}
|
||||
p.done = len(p.selection()) > 0
|
||||
p.done = p.count() > 0
|
||||
case "up", "ctrl+p":
|
||||
p.cursor = max(0, p.cursor-1)
|
||||
case "down", "ctrl+n":
|
||||
@@ -115,7 +145,7 @@ func (p *picker) finished() bool { return p.done }
|
||||
|
||||
func (p *picker) view() string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "%s %s\n", bold.Render(p.title), dim.Render(fmt.Sprintf("%d selected", len(p.selection()))))
|
||||
fmt.Fprintf(&b, "%s %s\n", bold.Render(p.title), dim.Render(fmt.Sprintf("%d selected", p.count())))
|
||||
fmt.Fprintf(&b, "filter: %s%s\n\n", p.filter, dim.Render("▏"))
|
||||
|
||||
vis := p.visible()
|
||||
@@ -133,7 +163,11 @@ func (p *picker) view() string {
|
||||
case p.picked[vis[row]]:
|
||||
box = green.Render("[x]")
|
||||
}
|
||||
line := fmt.Sprintf("%s %s %s", box, pad(s.Name, nameWidth), dim.Render(s.Path))
|
||||
kind := ""
|
||||
if s.agent {
|
||||
kind = cyan.Render("agent") + " "
|
||||
}
|
||||
line := fmt.Sprintf("%s %s %s%s", box, pad(s.Name, nameWidth), kind, dim.Render(s.Path))
|
||||
if row == p.cursor {
|
||||
line = selected.Render("›") + " " + line
|
||||
} else {
|
||||
@@ -142,7 +176,7 @@ func (p *picker) view() string {
|
||||
b.WriteString(line + "\n")
|
||||
}
|
||||
if len(vis) == 0 {
|
||||
b.WriteString(dim.Render(" no skills match") + "\n")
|
||||
b.WriteString(dim.Render(" nothing matches") + "\n")
|
||||
}
|
||||
body := fit(b.String(), p.width, p.height-1)
|
||||
return body + "\n" + dim.Render("type to filter · ↑/↓ move · space toggle · ctrl+a toggle all · enter add · esc cancel")
|
||||
|
||||
@@ -44,13 +44,13 @@ func screen(c component) string { return ansi.Strip(c.view()) }
|
||||
|
||||
func TestPicker(t *testing.T) {
|
||||
items := []skills.Skill{{Name: "tdd", Path: "a/tdd"}, {Name: "grilling", Path: "b/grilling"}, {Name: "tdd", Path: "c/tdd"}}
|
||||
p := newPicker("add from x", items, map[string]bool{"b/grilling": true})
|
||||
p := newPicker("add from x", items, nil, map[string]bool{"b/grilling": true})
|
||||
p.resize(80, 20)
|
||||
|
||||
// Installed skills can't be picked, and enter needs a selection.
|
||||
feed(p, press("grill", "space", "enter"))
|
||||
if p.done || len(p.selection()) != 0 {
|
||||
t.Fatalf("picked an installed skill: done=%v %v", p.done, p.selection())
|
||||
if p.done || p.count() != 0 {
|
||||
t.Fatalf("picked an installed skill: done=%v picked=%d", p.done, p.count())
|
||||
}
|
||||
if !strings.Contains(screen(p), "[•] grilling") {
|
||||
t.Errorf("installed marker missing:\n%s", screen(p))
|
||||
@@ -60,17 +60,109 @@ func TestPicker(t *testing.T) {
|
||||
if !p.done || p.canceled {
|
||||
t.Fatalf("done=%v canceled=%v", p.done, p.canceled)
|
||||
}
|
||||
if got := p.selection(); !reflect.DeepEqual(got, []skills.Skill{items[0], items[2]}) {
|
||||
t.Errorf("selection %v", got)
|
||||
if got, agents := p.selection(); !reflect.DeepEqual(got, []skills.Skill{items[0], items[2]}) || len(agents) != 0 {
|
||||
t.Errorf("selection %v %v", got, agents)
|
||||
}
|
||||
|
||||
p = newPicker("x", items, nil)
|
||||
p = newPicker("x", items, nil, nil)
|
||||
feed(p, press("esc"))
|
||||
if !p.canceled {
|
||||
t.Error("esc should cancel")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPickerAgents(t *testing.T) {
|
||||
sk := []skills.Skill{{Name: "tdd", Path: "skills/tdd"}}
|
||||
ag := []skills.Skill{{Name: "comment-sicko", Path: "pstack/agents/comment-sicko.md"}, {Name: "poteto-agent", Path: "pstack/agents/poteto-agent.md"}}
|
||||
p := newPicker("add from x", sk, ag, map[string]bool{"pstack/agents/poteto-agent.md": true})
|
||||
p.resize(100, 20)
|
||||
|
||||
s := screen(p)
|
||||
if !strings.Contains(s, "comment-sicko") || !strings.Contains(s, "agent pstack/agents/comment-sicko.md") {
|
||||
t.Errorf("agents should be listed and tagged:\n%s", s)
|
||||
}
|
||||
if !strings.Contains(s, "[•] poteto-agent") {
|
||||
t.Errorf("installed agent marker missing:\n%s", s)
|
||||
}
|
||||
|
||||
// Skills come first; pick the skill and the agent, not the installed one.
|
||||
feed(p, press("space", "down", "space", "down", "space", "enter"))
|
||||
if !p.done {
|
||||
t.Fatal("enter should finish")
|
||||
}
|
||||
gotSkills, gotAgents := p.selection()
|
||||
if !reflect.DeepEqual(gotSkills, sk) || !reflect.DeepEqual(gotAgents, ag[:1]) {
|
||||
t.Errorf("selection %v / %v", gotSkills, gotAgents)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardAddAgent(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
repo := t.TempDir()
|
||||
for rel, body := range map[string]string{
|
||||
"skills/tdd/SKILL.md": "tdd",
|
||||
"pstack/agents/sicko.md": "---\nname: sicko\n---\n",
|
||||
"harness/agents/sicko.md": "---\nname: sicko\n---\n",
|
||||
"pstack/agents/README.md": "# agents",
|
||||
"pstack/agents/another.md": "---\nname: another\n---\n",
|
||||
"skills/tdd/notes/inner.md": "x",
|
||||
} {
|
||||
path := filepath.Join(repo, rel)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(body), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
store := core.Store{Dir: t.TempDir(), Fetcher: oneRev{"github:cursor/plugins": repo}}
|
||||
d := newDashboard(ctx, store)
|
||||
d.Update(tea.WindowSizeMsg{Width: 100, Height: 24})
|
||||
|
||||
found, agents, installed, err := store.Available(ctx, core.AddRequest{URL: "github:cursor/plugins"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d.Update(availableMsg{"github:cursor/plugins", found, agents, installed, nil})
|
||||
if d.mode != modeSub {
|
||||
t.Fatalf("mode = %v, want the picker open", d.mode)
|
||||
}
|
||||
|
||||
// Rows: tdd, then agents another, sicko (harness), sicko (pstack). Pick the pstack sicko.
|
||||
d.sub.(*picker).filter = "pstack/agents/sicko"
|
||||
d.key(tea.KeyPressMsg{Code: tea.KeySpace, Text: " "})
|
||||
cmd := d.key(tea.KeyPressMsg{Code: tea.KeyEnter})
|
||||
if cmd == nil {
|
||||
t.Fatal("finishing the picker should start the add")
|
||||
}
|
||||
msg := cmd()
|
||||
if batch, ok := msg.(tea.BatchMsg); ok {
|
||||
for _, c := range batch {
|
||||
if c != nil {
|
||||
if m, ok := c().(doneMsg); ok {
|
||||
msg = m
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
done, ok := msg.(doneMsg)
|
||||
if !ok {
|
||||
t.Fatalf("want the add to finish with a doneMsg, got %T", msg)
|
||||
}
|
||||
d.Update(done)
|
||||
|
||||
list, err := store.List()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(list) != 1 || !list[0].Agent || list[0].Name != "sicko" || list[0].Path != "pstack/agents/sicko.md" {
|
||||
t.Errorf("store has %+v, want only the pstack sicko agent", list)
|
||||
}
|
||||
if s := ansi.Strip(d.render()); !strings.Contains(s, "sicko (agent)") {
|
||||
t.Errorf("dashboard should show the agent:\n%s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReview(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
write := func(rel, content string) string {
|
||||
|
||||
Reference in new issue
Block a user