library: ZCode gets the library — its instructions go to ~/.zcode/AGENTS.md, its skills to ~/.zcode/skills and its MCP servers to ~/.zcode/cli/config.json's mcp.servers, where ZCode's own MCP settings keep them (a server of the user's there, and the file's other keys, stay as they are). magpie library … agents no longer takes an agent it has no place in for that: an unknown one, or one without MCP (omp) or instructions (Cursor), is refused with why, instead of recorded and given nothing (asked on Discord)
This commit is contained in:
+11
-3
@@ -88,6 +88,7 @@ const (
|
||||
fmtGoose
|
||||
fmtPi
|
||||
fmtDesktop
|
||||
fmtZCode
|
||||
)
|
||||
|
||||
// mcpFile is the file an agent keeps its user-wide MCP servers in.
|
||||
@@ -105,6 +106,8 @@ func (f *mcpFile) key() string {
|
||||
return "mcp"
|
||||
case fmtGoose:
|
||||
return "extensions"
|
||||
case fmtZCode:
|
||||
return "mcp.servers"
|
||||
}
|
||||
return "mcpServers"
|
||||
}
|
||||
@@ -181,7 +184,7 @@ func (f *mcpFile) encode(s *Server) ordered {
|
||||
}
|
||||
}
|
||||
switch f.Format {
|
||||
case fmtClaude, fmtCrush:
|
||||
case fmtClaude, fmtCrush, fmtZCode:
|
||||
add("type", s.Transport)
|
||||
if s.Remote() {
|
||||
add("url", s.URL)
|
||||
@@ -362,7 +365,7 @@ func (f *mcpFile) decode(name string, m map[string]any) (*Server, bool) {
|
||||
} else {
|
||||
local(str(m, "command"), m["args"], m["env"])
|
||||
}
|
||||
default: // Claude Code, Cursor, Copilot, Crush
|
||||
default: // Claude Code, Cursor, Copilot, Crush, ZCode
|
||||
t := str(m, "type")
|
||||
if u := str(m, "url"); u != "" {
|
||||
if t != "sse" {
|
||||
@@ -401,7 +404,11 @@ func (f *mcpFile) entries() (map[string]map[string]any, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", f.Path, err)
|
||||
}
|
||||
all, _ := doc[f.key()].(map[string]any)
|
||||
// the key can be a path: ZCode keeps them in mcp.servers
|
||||
var all map[string]any = doc
|
||||
for _, k := range strings.Split(f.key(), ".") {
|
||||
all, _ = all[k].(map[string]any)
|
||||
}
|
||||
for name, v := range all {
|
||||
if m, ok := v.(map[string]any); ok {
|
||||
out[name] = m
|
||||
@@ -436,6 +443,7 @@ var owned = map[mcpFormat][]string{
|
||||
fmtCodex: {"url", "http_headers", "command", "args", "env"},
|
||||
fmtDesktop: {"url", "headers", "command", "args", "env"},
|
||||
fmtPi: {"transport", "httpTransport", "url", "headers", "command", "args", "env"},
|
||||
fmtZCode: {"type", "url", "headers", "command", "args", "env"},
|
||||
}
|
||||
|
||||
// merged is the entry magpie writes, with what the user added to the old
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
)
|
||||
@@ -116,6 +118,13 @@ func targetOf(a *agent.Agent) *Target {
|
||||
t.MCP = &mcpFile{Path: a.Path, Format: fmtCrush}
|
||||
t.Skills = filepath.Join(filepath.Dir(a.Path), "skills")
|
||||
t.SkillsAlso = []string{"claude"}
|
||||
case "zcode":
|
||||
// ZCode's own servers are its cli/config.json's mcp.servers (the
|
||||
// app's MCP settings write there); AGENTS.md and skills beside it
|
||||
d := filepath.Join(h, ".zcode")
|
||||
t.Instructions = filepath.Join(d, "AGENTS.md")
|
||||
t.MCP = &mcpFile{Path: filepath.Join(d, "cli", "config.json"), Format: fmtZCode}
|
||||
t.Skills = filepath.Join(d, "skills")
|
||||
case "claude-desktop":
|
||||
// Claude Desktop reads only commands from its file: a remote server
|
||||
// is added in its own Connectors settings
|
||||
@@ -161,3 +170,39 @@ func targetByID(id string) *Target {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Takes is the id of the agent q names (its id, an alias, its name) when
|
||||
// the library can give it kind — "instructions", "mcp" or "skills" — or
|
||||
// why not: an agent it has no place for isn't recorded as getting it and
|
||||
// then given nothing.
|
||||
func Takes(q, kind string) (string, error) {
|
||||
var a *agent.Agent
|
||||
for _, app := range apps() {
|
||||
if strings.EqualFold(app.ID, q) || strings.EqualFold(app.Name, q) {
|
||||
a = app
|
||||
}
|
||||
}
|
||||
if a == nil {
|
||||
var err error
|
||||
if a, err = agent.Find(q); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
t := targetOf(a)
|
||||
var has bool
|
||||
what := map[string]string{"instructions": "instructions", "mcp": "MCP servers", "skills": "skills"}[kind]
|
||||
if t != nil {
|
||||
switch kind {
|
||||
case "instructions":
|
||||
has = t.Instructions != ""
|
||||
case "mcp":
|
||||
has = t.MCP != nil
|
||||
case "skills":
|
||||
has = t.Skills != ""
|
||||
}
|
||||
}
|
||||
if !has {
|
||||
return "", fmt.Errorf("%s has no user-wide place for %s that magpie knows of", a.Name, what)
|
||||
}
|
||||
return a.ID, nil
|
||||
}
|
||||
|
||||
+29
-4
@@ -60,7 +60,10 @@ func libraryCmd(args []string) error {
|
||||
text := string(b)
|
||||
res, err = library.SaveInstructions(library.InstructionsChange{Shared: &text})
|
||||
case rest[0] == "agents" && len(rest) == 2:
|
||||
res, err = library.SaveInstructions(library.InstructionsChange{Agents: agentList(rest[1])})
|
||||
var as []string
|
||||
if as, err = libraryAgents(rest[1], "instructions"); err == nil {
|
||||
res, err = library.SaveInstructions(library.InstructionsChange{Agents: as})
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("usage:\n %s", libraryUsage)
|
||||
}
|
||||
@@ -71,7 +74,9 @@ func libraryCmd(args []string) error {
|
||||
var cmd []string
|
||||
for _, a := range rest[2:] {
|
||||
if v, ok := strings.CutPrefix(a, "agents="); ok {
|
||||
s.Agents = agentList(v)
|
||||
if s.Agents, err = libraryAgents(v, "mcp"); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
cmd = append(cmd, a)
|
||||
}
|
||||
@@ -89,7 +94,10 @@ func libraryCmd(args []string) error {
|
||||
}
|
||||
res, err = library.SaveServer("", s)
|
||||
case len(rest) == 3 && rest[0] == "agents":
|
||||
res, err = library.ServerAgents(rest[1], agentList(rest[2]))
|
||||
var as []string
|
||||
if as, err = libraryAgents(rest[2], "mcp"); err == nil {
|
||||
res, err = library.ServerAgents(rest[1], as)
|
||||
}
|
||||
case len(rest) == 2 && rest[0] == "rm":
|
||||
res, err = library.RemoveServer(rest[1])
|
||||
default:
|
||||
@@ -98,7 +106,10 @@ func libraryCmd(args []string) error {
|
||||
case "skill", "skills":
|
||||
switch {
|
||||
case len(rest) == 3 && rest[0] == "agents":
|
||||
res, err = library.SkillAgents(rest[1], agentList(rest[2]))
|
||||
var as []string
|
||||
if as, err = libraryAgents(rest[2], "skills"); err == nil {
|
||||
res, err = library.SkillAgents(rest[1], as)
|
||||
}
|
||||
case len(rest) == 2 && rest[0] == "rm":
|
||||
res, err = library.RemoveSkill(rest[1])
|
||||
default:
|
||||
@@ -128,6 +139,20 @@ func agentList(s string) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// libraryAgents is agentList with each agent's id, refused when the library
|
||||
// has no place in it for kind.
|
||||
func libraryAgents(s, kind string) ([]string, error) {
|
||||
out := []string{}
|
||||
for _, a := range agentList(s) {
|
||||
id, err := library.Takes(a, kind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, id)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func printLibraryResult(res *library.Result) {
|
||||
if len(res.Changed) == 0 {
|
||||
fmt.Println(green.Render("✓"), "every agent already has it")
|
||||
|
||||
Reference in New Issue
Block a user