library: an agent not installed is on no row but those of what it still has (@jiahao_jayden on X)
Library → Skills showed a chip for WorkBuddy on every row though it
wasn't installed ("一排有点密恐了"). WorkBuddy has no CLI and no detect
rule, so it counted as installed whenever ~/.workbuddy (or its
models.json) existed; that folder stays after the app is trashed, and
magpie itself writes models.json, mcp.json and skills/ there.
- agent: on a Mac WorkBuddy and WorkBuddy AI are detected by their apps,
each by its own bundle id (com.tencent.workbuddy.mac,
com.workbuddy.workbuddy-ai) in /Applications or ~/Applications
(macBundle). Off a Mac the folder still counts, as before.
- library: an agent that isn't a target but still has skills, servers or
hooks magpie gave it is held (Target.Gone). A sync takes edits from its
copies and then only takes things out of it; Read lists it with
gone: true while it has any, and not once it has none.
- GUI: a gone agent's chip is only on the rows of what it has, lit; a
click takes it away. All, the How-per-agent sheet and the pickers leave
it out; By agent lists it as "Not installed here" with Turn all on off.
No layout change. New strings in zh, zh-TW, ja, de.
Run at this tree (macOS, sandbox HOME, Go caches pinned):
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./...: clean. go build, GOOS=linux go build -tags
nogui, GOOS=windows go build: ok.
- go test -tags nogui -timeout 30m ./...: all ok (59 packages);
internal/gui rerun after the last string rename: ok.
- GUI: the 74 test files that open the Library, chromium and webkit:
563/563 each. library-gone-agents.test.cjs (new; 1100px and 390px, en,
zh, zh-TW, ja, de): 11/11 in both; i18n-keys.test.cjs: 3/3.
Broken by hand, each went red, then restored and green:
- old client.js: library-gone-agents fails "a chip for an agent not
installed on a row it has nothing on".
- workbuddyHere's Mac branch falling back to the folder:
TestWorkBuddyOnMacIsItsApp "no app, only the folders: WorkBuddy true,
WorkBuddy AI true".
- syncSkills' Gone guard off: TestGoneAgentListedToTakeOut "a sync gave
the gone hermes a skill again".
- held() returning nil: "hermes, holding a skill and a server, isn't
listed as gone".
- the gone sync steps skipped: "hermes, holding nothing, is still listed".
Not verified: the reporter's machine; WorkBuddy detection on Windows and
Linux (unchanged, still by folder); other agents detected by folder alone
(zcode, alma, grok-app, air, hanako, morph, grok) are unchanged. WorkBuddy
AI.app is installed on the owner's Mac without ~/.workbuddy-ai, so it now
shows as detected there.
This commit is contained in:
@@ -14,7 +14,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
| --- | --- | --- |
|
||||
| library.json | `Library` holds the instruction sets, the MCP servers, the skills, the projects, skill groups and copy settings. `Applied` records what magpie last wrote into each agent, so it only ever takes away its own. The instruction texts and skill folders live under `Dir` (`library/` in magpie's config folder). | [`library.go`](../../internal/library/library.go) |
|
||||
| One change | `change` locks the library, loads it, applies one edit, saves, syncs every agent and saves again. Every exported mutation (`SaveServer`, `InstallSkills`, `SetSkillHow` and the rest) goes through it. One change runs at a time, whether from the page or the CLI. | [`library.go`](../../internal/library/library.go) |
|
||||
| Targets | `Targets` lists the detected agents (`agent.Detected`), plus apps like Claude Desktop, with where each keeps its instructions file (and an `Override` it reads instead), its MCP file and its skills folder. An agent whose CLI is gone (`CLIMissing`: an uninstall that left the folder behind, #2177, #2254) is no target: it is given nothing it can't read, and what is already written there stays. `everyTarget` keeps it for the guards that refuse an agent's own places: a project folder whose skills folder or MCP file is the agent's, and an instruction set kept in its instructions file. An agent in a running WSL distro has its places under the distro's home (`wslTargetOf`): Claude Code, Codex, Pi and OmO each by its own rule, and every agent that keeps all of them in its own folder (Hermes Agent, omp, OpenCode, Droid and the rest of `ownFolder`, #1323) by the same rule as on this machine, its MCP file marked as WSL's so a Windows program isn't given to it. An agent a plugin adds (`a.Plugin`) has the places its plugin's `agent.library` names (`pluginTarget`): an instructions file, an MCP file in one of `agentplug.MCPFormats` (each the `mcpFormat` of the agent it is named for, `pluginMCP`) and a skills folder, `~` and `$VAR` expanded as its config is; one that names none is no target. Before, a plugin's agent got models and keys only. | [`targets.go`](../../internal/library/targets.go) |
|
||||
| Targets | `Targets` lists the detected agents (`agent.Detected`), plus apps like Claude Desktop, with where each keeps its instructions file (and an `Override` it reads instead), its MCP file and its skills folder. An agent whose CLI is gone (`CLIMissing`: an uninstall that left the folder behind, #2177, #2254) is no target: it is given nothing it can't read. One that isn't a target but still has skills, servers or hooks magpie gave it (in `Applied`, or listed in an item's `Agents`) is held (`held`, a `Target` with `Gone`): a sync takes edits from its copies and then only takes out of it (`syncSkills`, `syncMCP` and `syncHooks` give a gone target nothing new), and `Read` lists it with `gone: true` while it has any. The page shows a gone agent's chip only on the rows of what it has, lit, so a click takes it out (`withGone` in plugins/library/client.js), leaves it out of All, the per-agent How sheet and every picker, and lists it in By agent as Not installed here with Turn all on off (@jiahao_jayden on X: an uninstalled WorkBuddy was on every skill's row; `TestGoneAgentListedToTakeOut`, `library-gone-agents.test.cjs`). On a Mac WorkBuddy and WorkBuddy AI are detected by their apps' bundle ids (`com.tencent.workbuddy.mac`, `com.workbuddy.workbuddy-ai`, `macBundle`), not by `~/.workbuddy`, which an uninstall leaves and magpie itself writes into (`TestWorkBuddyOnMacIsItsApp`); off a Mac the folder still counts. `everyTarget` keeps it for the guards that refuse an agent's own places: a project folder whose skills folder or MCP file is the agent's, and an instruction set kept in its instructions file. An agent in a running WSL distro has its places under the distro's home (`wslTargetOf`): Claude Code, Codex, Pi and OmO each by its own rule, and every agent that keeps all of them in its own folder (Hermes Agent, omp, OpenCode, Droid and the rest of `ownFolder`, #1323) by the same rule as on this machine, its MCP file marked as WSL's so a Windows program isn't given to it. An agent a plugin adds (`a.Plugin`) has the places its plugin's `agent.library` names (`pluginTarget`): an instructions file, an MCP file in one of `agentplug.MCPFormats` (each the `mcpFormat` of the agent it is named for, `pluginMCP`) and a skills folder, `~` and `$VAR` expanded as its config is; one that names none is no target. Before, a plugin's agent got models and keys only. | [`targets.go`](../../internal/library/targets.go) |
|
||||
| Sync | `sync` writes each target's instructions and MCP servers. It then takes edits made in agents' skill copies into the library (`takeEdits`) and links or copies the skills. `~/.agents/skills` goes first, so an agent that reads it gets no second link. Then it syncs projects' skills. | [`sync.go`](../../internal/library/sync.go) |
|
||||
| Projects | A project (`Project`) is a folder given some of the library's skills and MCP servers, each for some agents. A skill is linked (or copied) into the folder the agent reads a project's skills from (`projectSkillsDirs`): `.claude/skills` for Claude Code, `.qoder/skills` for Qoder and Qoder CN, `.codebuddy/skills` for CodeBuddy Code, `.commandcode/skills` for Command Code, and `.agents/skills` for Codex, Gemini CLI, OpenCode, Pi, Cursor, Copilot CLI, Antigravity, Kimi, Goose, Grok, Droid and Cline. A server is written into the file the agent reads a project's servers from (`projectMCPFiles`), in the shape its user-wide file has: `.mcp.json` for Claude Code and CodeBuddy Code (CodeBuddy's `mcp.json` when the project has that and no `.mcp.json`, since it reads only the first of the two), `.codex/config.toml`, `.gemini/settings.json`, `.cursor/mcp.json`, `opencode.json`, `.zcode/config.json`, `.pi/mcp.json`, `.qoder/settings.json`'s `mcpServers` for Qoder and Qoder CN, and `.factory/mcp.json` for Droid. Claude Code, Qoder and CodeBuddy ask the user to approve a project's server before using it. Only targets whose vendor source or docs name them are listed (each map's comment cites them); an agent with none (Copilot CLI's MCP, Zed, WorkBuddy, Command Code's MCP, whose `.mcp.json` has its own `transport` shape) can't be picked for a project (eirc on Discord). `Placed`, `Wrote`, `Made` and `MadeFiles` record what magpie put there, the only things it takes away, and what it made is listed in the project's `.gitignore`. | [`projects.go`](../../internal/library/projects.go), [`project_mcp.go`](../../internal/library/project_mcp.go) |
|
||||
| Instructions | magpie's part of an agent's instructions file sits between two marker lines. The rest of the file is the user's. Several named sets can be switched between (#106). A set can be kept in a file of the user's own instead of `instruction-sets/` (`InstrSet.File`, 新v学员 on Discord): `~/.agents/AGENTS.md`, which Droid and omp read too. `textPath` reads it, `putText` keeps it aside and writes it but never removes it, removing the set lets go of it, and `linkable` refuses a file magpie writes into (an agent's own instructions, a file with the marker line), the library's own and another set's. The app's `KeepLinked` looks at the file every 30 s and writes a change into the agents (`SyncLinked`). `Collect` carries the set's text, not where its file is; `Put` keeps this computer's file for the set and never empties it for a text not carried. | [`instructions.go`](../../internal/library/instructions.go) |
|
||||
@@ -72,7 +72,7 @@ agents RTK, a CLI that cuts shell output down before the model reads it.
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
go test -tags nogui ./internal/library -run 'TestReadLooksAtEachFolderOnce|TestLinkChangedBetweenVisitsShows|TestUnreadablePartIsLookedAtAgain|TestCheckSkillsFindsNewOnes|TestNewBase|TestUpdateKeeps|TestCheckDue|TestCheckSkillsMarksItDone|TestTargets|TestServer|TestImportServer|TestCheck|TestInstructions|TestInstructionSets|TestLinkedSet|TestLinkRefused|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie|TestCarry|TestPageReadDoesntReadUnchangedSkillsAgain|TestJustWrittenSkillIsReadAgain|TestUnreadableSkillIsntRememberedAsDifferent|TestGlanceLeavesOutTheAgentsSkills|TestPluginAgent|TestPluginMCPFormatsAreWritten|TestToolsOff|TestOffList|TestHooks|TestCheckRenewsMagpiesSignIn|TestCheckSaysSignInRanOut|TestSignInAsTheUsersOwnApp|TestOAuthAppChecked|TestOAuthAppSecretCarried'
|
||||
go test -tags nogui ./internal/library -run 'TestReadLooksAtEachFolderOnce|TestLinkChangedBetweenVisitsShows|TestUnreadablePartIsLookedAtAgain|TestCheckSkillsFindsNewOnes|TestNewBase|TestUpdateKeeps|TestCheckDue|TestCheckSkillsMarksItDone|TestTargets|TestServer|TestImportServer|TestCheck|TestInstructions|TestInstructionSets|TestLinkedSet|TestLinkRefused|TestSkill|TestRemoveFoundSkill|TestInstallSet|TestInstallLists|TestEverySkillAgents|TestEveryServerAgents|TestSomeServersAgents|TestRemoveServers|TestRTK|TestEnvRefs|TestDshRefRoundTrip|TestDshImportKeepsJS|TestAgentMCPFiles|TestCodeBuddyMCPFile|TestZedMCP|TestOwnServerFromElsewhereRunsThisMagpie|TestUsersOwnServerStaysAsItIs|TestCarriedOwnServerIsEachComputersMagpie|TestCarry|TestPageReadDoesntReadUnchangedSkillsAgain|TestJustWrittenSkillIsReadAgain|TestUnreadableSkillIsntRememberedAsDifferent|TestGlanceLeavesOutTheAgentsSkills|TestPluginAgent|TestPluginMCPFormatsAreWritten|TestToolsOff|TestOffList|TestHooks|TestCheckRenewsMagpiesSignIn|TestCheckSaysSignInRanOut|TestSignInAsTheUsersOwnApp|TestOAuthAppChecked|TestOAuthAppSecretCarried|TestGoneAgentListedToTakeOut'
|
||||
go test -race ./internal/mcpauth
|
||||
go test -tags nogui ./internal/library
|
||||
node --test internal/gui/tests/library-items.test.cjs internal/gui/tests/library-rtk-gain.test.cjs internal/gui/tests/library-rtk-nohook.test.cjs internal/gui/tests/library-servers-bulk.test.cjs internal/gui/tests/library-pick-remove.test.cjs internal/gui/tests/library-env-refs.test.cjs internal/gui/tests/library-zed-mcp.test.cjs internal/gui/tests/library-workbuddy-trust.test.cjs internal/gui/tests/skill-new-in-repo.test.cjs internal/gui/tests/skill-update-edited.test.cjs internal/gui/tests/remove-found-skill.test.cjs internal/gui/tests/found-skill-pick-remove.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/library-mcp-tools.test.cjs internal/gui/tests/library-mcp-tool-switch.test.cjs internal/gui/tests/library-hooks.test.cjs internal/gui/tests/library-mcp-health.test.cjs internal/gui/tests/mcp-signin-health.test.cjs internal/gui/tests/mcp-signin.test.cjs internal/gui/tests/mcp-editor-cancel.test.cjs internal/gui/tests/mcp-oauth-app.test.cjs
|
||||
|
||||
@@ -83,6 +83,24 @@ var (
|
||||
plistVersionRe = regexp.MustCompile(`<key>CFBundleShortVersionString</key>\s*<string>([^<]+)</string>`)
|
||||
)
|
||||
|
||||
// macBundle reports whether app's bundle is in one of appFolders, under one
|
||||
// of its names: with its bundle id, or an Info.plist that isn't XML (a
|
||||
// binary one says nothing either way, and the name is the app's own).
|
||||
func macBundle(app desktopApp) bool {
|
||||
for _, dir := range appFolders() {
|
||||
for _, name := range app.names {
|
||||
b, err := os.ReadFile(filepath.Join(dir, name, "Contents", "Info.plist"))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if id := plistIDRe.FindSubmatch(b); id == nil || strings.TrimSpace(string(id[1])) == app.id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// AppVersion is the version of the agent's desktop app installed here, ""
|
||||
// for an agent without one magpie knows, one not installed, or an Info.plist
|
||||
// that doesn't say (a binary one isn't read).
|
||||
|
||||
@@ -31,7 +31,9 @@ import (
|
||||
"bytes"
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"slices"
|
||||
|
||||
"github.com/yetone/magpie/internal/appdir"
|
||||
@@ -44,24 +46,51 @@ func workbuddy(home string) *Agent {
|
||||
if dir == "" {
|
||||
dir = filepath.Join(home, ".workbuddy")
|
||||
}
|
||||
return workbuddyBuild("workbuddy", "WorkBuddy", dir, []string{"work-buddy"})
|
||||
return workbuddyBuild("workbuddy", "WorkBuddy", dir, []string{"work-buddy"}, desktopApp{id: "com.tencent.workbuddy.mac", names: []string{"WorkBuddy.app"}})
|
||||
}
|
||||
|
||||
// workbuddyAI is WorkBuddy AI, the international build, in ~/.workbuddy-ai.
|
||||
// WORKBUDDY_CONFIG_DIR is WorkBuddy's (workbuddy above): both builds would
|
||||
// read a folder it names, which that agent writes already.
|
||||
func workbuddyAI(home string) *Agent {
|
||||
return workbuddyBuild("workbuddy-ai", "WorkBuddy AI", filepath.Join(home, ".workbuddy-ai"), []string{"workbuddy-intl", "workbuddyai"})
|
||||
return workbuddyBuild("workbuddy-ai", "WorkBuddy AI", filepath.Join(home, ".workbuddy-ai"), []string{"workbuddy-intl", "workbuddyai"}, desktopApp{id: "com.workbuddy.workbuddy-ai", names: []string{"WorkBuddy AI.app"}})
|
||||
}
|
||||
|
||||
// workbuddyBuild is one of WorkBuddy's builds, its models.json in dir.
|
||||
func workbuddyBuild(id, name, dir string, aliases []string) *Agent {
|
||||
// workbuddyOnMac says whether WorkBuddy is found by its app bundle, as on a
|
||||
// Mac; a var so a test forces either OS.
|
||||
var workbuddyOnMac = func() bool { return runtime.GOOS == "darwin" }
|
||||
|
||||
// workbuddyHere reports whether a WorkBuddy build is installed. On a Mac it
|
||||
// is its app bundle (app): its data folder is no sign of it. Dragging
|
||||
// WorkBuddy.app to the Trash leaves ~/.workbuddy behind, and magpie writes
|
||||
// there itself (models.json when wired, mcp.json and skills/ from the
|
||||
// library), so the folder alone kept an uninstalled WorkBuddy on every
|
||||
// library row for good (@jiahao_jayden on X: 没安装的 WorkBuddy 也在技能
|
||||
// 那一排). Elsewhere, where magpie doesn't know its install folder, the
|
||||
// folder still counts, as before.
|
||||
func workbuddyHere(dir, path string, app desktopApp) bool {
|
||||
if Taken(dir) {
|
||||
return false
|
||||
}
|
||||
if workbuddyOnMac() {
|
||||
return macBundle(app)
|
||||
}
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
return true
|
||||
}
|
||||
return agentDir(dir)
|
||||
}
|
||||
|
||||
// workbuddyBuild is one of WorkBuddy's builds, its models.json in dir and
|
||||
// app its macOS bundle.
|
||||
func workbuddyBuild(id, name, dir string, aliases []string, app desktopApp) *Agent {
|
||||
path := filepath.Join(dir, "models.json")
|
||||
write := func(on bool) error { return buddyWrite(path, id, on) }
|
||||
return &Agent{
|
||||
ID: id, Name: name, Icon: "workbuddy-color", Aliases: aliases,
|
||||
UA: []string{id},
|
||||
Dir: dir, Path: path,
|
||||
detect: func() bool { return workbuddyHere(dir, path, app) },
|
||||
Sync: func() error {
|
||||
if !workbuddyWired(path) {
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// notOnMac has WorkBuddy found as off a Mac, by its folder, for the test.
|
||||
func notOnMac(t *testing.T) {
|
||||
was := workbuddyOnMac
|
||||
workbuddyOnMac = func() bool { return false }
|
||||
t.Cleanup(func() { workbuddyOnMac = was })
|
||||
}
|
||||
|
||||
// @jiahao_jayden on X: an uninstalled WorkBuddy was on every row of the
|
||||
// library. On a Mac WorkBuddy is there by its app: ~/.workbuddy stays
|
||||
// behind when WorkBuddy.app is dragged to the Trash, and magpie writes
|
||||
// there itself (models.json, mcp.json, skills/), so the folder, whatever
|
||||
// it holds, is no sign of it. Each build is known by its own bundle id.
|
||||
func TestWorkBuddyOnMacIsItsApp(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
t.Setenv("USERPROFILE", home)
|
||||
t.Setenv("WORKBUDDY_CONFIG_DIR", "")
|
||||
apps, userApps := t.TempDir(), t.TempDir()
|
||||
was, wasMac := appFolders, workbuddyOnMac
|
||||
appFolders = func() []string { return []string{apps, userApps} }
|
||||
workbuddyOnMac = func() bool { return true }
|
||||
t.Cleanup(func() { appFolders, workbuddyOnMac = was, wasMac })
|
||||
plist := func(id string) string {
|
||||
return `<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict><key>CFBundleIdentifier</key><string>` + id + `</string><key>CFBundleShortVersionString</key><string>5.6.2</string></dict></plist>`
|
||||
}
|
||||
// what an uninstall leaves, and what magpie wrote there itself
|
||||
for _, d := range []string{".workbuddy", ".workbuddy-ai"} {
|
||||
for _, f := range []string{"models.json", "mcp.json", "argv.json"} {
|
||||
p := filepath.Join(home, d, f)
|
||||
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(p, []byte("[]"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(home, d, "skills", "pdf"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
cn, intl := workbuddy(home), workbuddyAI(home)
|
||||
if cn.Detected() || intl.Detected() {
|
||||
t.Fatalf("no app, only the folders: WorkBuddy %v, WorkBuddy AI %v", cn.Detected(), intl.Detected())
|
||||
}
|
||||
|
||||
// the international build's app, in /Applications: it alone is there,
|
||||
// with no folder of its own yet too
|
||||
os.RemoveAll(filepath.Join(home, ".workbuddy-ai"))
|
||||
installApp(t, apps, "WorkBuddy AI.app", plist("com.workbuddy.workbuddy-ai"))
|
||||
if cn.Detected() || !intl.Detected() {
|
||||
t.Fatalf("WorkBuddy AI.app: WorkBuddy %v, WorkBuddy AI %v", cn.Detected(), intl.Detected())
|
||||
}
|
||||
|
||||
// another app under WorkBuddy's name is not WorkBuddy
|
||||
installApp(t, userApps, "WorkBuddy.app", plist("com.example.other"))
|
||||
if cn.Detected() {
|
||||
t.Fatal("another bundle id taken for WorkBuddy")
|
||||
}
|
||||
// the China build's, in ~/Applications
|
||||
installApp(t, userApps, "WorkBuddy.app", plist("com.tencent.workbuddy.mac"))
|
||||
if !cn.Detected() {
|
||||
t.Fatal("WorkBuddy.app installed: not detected")
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ func TestWorkBuddy(t *testing.T) {
|
||||
return ms
|
||||
}
|
||||
|
||||
// found by its folder, as off a Mac (TestWorkBuddyOnMacIsItsApp)
|
||||
notOnMac(t)
|
||||
a := workbuddy(home)
|
||||
if !a.Detected() {
|
||||
t.Fatal("not detected")
|
||||
@@ -214,6 +216,7 @@ func TestWorkBuddyAIWritesItsOwnFolder(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(home, ".workbuddy-ai", "argv.json"), []byte("{}"), 0o644)
|
||||
os.WriteFile(filepath.Join(home, ".workbuddy-ai", "device-id"), []byte("d"), 0o644)
|
||||
|
||||
notOnMac(t)
|
||||
a := workbuddyAI(home)
|
||||
if a.ID != "workbuddy-ai" || a.Path != intl {
|
||||
t.Fatalf("agent: %s at %s", a.ID, a.Path)
|
||||
|
||||
@@ -57,7 +57,11 @@ magpie.plugin("library", (ctx) => {
|
||||
// extension, which each of its chips says.
|
||||
// An agent hidden on the Agents page is left out here too (#71): what it
|
||||
// already has stays with it, and a new server or skill isn't given to it.
|
||||
const shownAgents = () => lib.agents.filter((a) => !isHidden(a));
|
||||
// One gone from this computer (gone: uninstalled, or its CLI) is listed
|
||||
// only on the rows of what it still has (withGone), for that to be taken
|
||||
// out: an agent that isn't installed was on every row (@jiahao_jayden).
|
||||
const shownAgents = () => lib.agents.filter((a) => !a.gone && !isHidden(a));
|
||||
const withGone = (all, on) => [...all, ...lib.agents.filter((a) => a.gone && (on || []).includes(a.id) && !all.some((x) => x.id === a.id))];
|
||||
const mcpAgents = () => shownAgents().filter((a) => a.mcp)
|
||||
.map((a) => a.mcpVia ? { ...a, aside: t("{agent} reads MCP servers through the {ext} extension", { agent: a.name, ext: a.mcpVia }) } : a);
|
||||
const skillAgents = () => shownAgents().filter((a) => a.skills);
|
||||
@@ -256,6 +260,7 @@ magpie.plugin("library", (ctx) => {
|
||||
// WebKit shows it no tooltip either — 蓝猫 clicked Claude Desktop's
|
||||
// grey chip for a remote server and nothing said why
|
||||
if (blocked) { c.classList.add("blocked"); c.setAttribute("aria-disabled", "true"); tip = blocked; }
|
||||
if (a.gone) { c.classList.add("gone"); tip = t("{agent} isn't installed here — click to take it away", { agent: a.name }); }
|
||||
c.title = a.aside && !problem && !blocked ? tip + "\n" + a.aside : tip;
|
||||
c.setAttribute("aria-pressed", has ? "true" : "false");
|
||||
// What's lit is read off the chips clicked, not the list they were
|
||||
@@ -300,7 +305,7 @@ magpie.plugin("library", (ctx) => {
|
||||
// bringing in servers) have it too (#1531): most start with every agent
|
||||
// lit, and one agent alone was a click on each of the others.
|
||||
function allChip(box, all, on, onChange) {
|
||||
const can = [...box.children].filter((c) => !cannot(c)).map((c) => c.dataset.agent);
|
||||
const can = [...box.children].filter((c) => !cannot(c) && !c.classList.contains("gone")).map((c) => c.dataset.agent);
|
||||
if (can.length < 2) return;
|
||||
const c = el("button", "lib-ag all", t("All"));
|
||||
c.dataset.all = "1";
|
||||
@@ -318,7 +323,7 @@ magpie.plugin("library", (ctx) => {
|
||||
function paintAll(box) {
|
||||
const c = box.querySelector(":scope > .lib-ag.all");
|
||||
if (!c) return;
|
||||
const can = [...box.children].filter((x) => x.dataset.agent && !cannot(x));
|
||||
const can = [...box.children].filter((x) => x.dataset.agent && !cannot(x) && !x.classList.contains("gone"));
|
||||
const n = can.length, full = can.every((x) => x.getAttribute("aria-pressed") === "true");
|
||||
c.classList.toggle("on", full);
|
||||
c.setAttribute("aria-pressed", full ? "true" : "false");
|
||||
@@ -1475,7 +1480,7 @@ magpie.plugin("library", (ctx) => {
|
||||
sub.title = serverLine(s);
|
||||
who.append(sub, toolsEl(s.name));
|
||||
row.append(mark(s.icon, s.transport === "stdio" ? GLYPH.cmd : GLYPH.web), who,
|
||||
agentChips(all, s.agents, chipsChange("servers/agents", s.name, "servers", (x) => serverRow(x, all)), { problems: s.problems, blocked: sseBlocked(s), all: true }));
|
||||
agentChips(withGone(all, s.agents), s.agents, chipsChange("servers/agents", s.name, "servers", (x) => serverRow(x, all)), { problems: s.problems, blocked: sseBlocked(s), all: true }));
|
||||
if (picking) return pickRow(row, s.name);
|
||||
row.onclick = () => editServer(s);
|
||||
row.title = t("Edit {name}", { name: s.name });
|
||||
@@ -2257,7 +2262,7 @@ magpie.plugin("library", (ctx) => {
|
||||
cmd.title = h.command;
|
||||
who.append(cmd);
|
||||
row.append(glyph(GLYPH.hook), who,
|
||||
agentChips(all, h.agents, chipsChange("hooks/agents", h.name, "hooks", (x) => hookRow(x, all)), { problems: h.problems, blocked: hookBlocked(h), all: true }));
|
||||
agentChips(withGone(all, h.agents), h.agents, chipsChange("hooks/agents", h.name, "hooks", (x) => hookRow(x, all)), { problems: h.problems, blocked: hookBlocked(h), all: true }));
|
||||
if (picking) return pickRow(row, h.name);
|
||||
row.onclick = () => editHook(h);
|
||||
row.title = t("Edit {name}", { name: h.name });
|
||||
@@ -3784,7 +3789,7 @@ magpie.plugin("library", (ctx) => {
|
||||
: t("An agent can have its own way; the others get links, as the library gives them.")));
|
||||
const list = el("div", "list lib-list lib-byagent-list");
|
||||
let busy = false;
|
||||
const draw = () => list.replaceChildren(...lib.agents.filter((a) => a.skills && (!isHidden(a) || a.howOwn)).map((a) => {
|
||||
const draw = () => list.replaceChildren(...lib.agents.filter((a) => a.skills && !a.gone && (!isHidden(a) || a.howOwn)).map((a) => {
|
||||
const row = el("div", "row lib-row lib-byagent-row lib-how-row");
|
||||
row.dataset.agent = a.id;
|
||||
const who = el("div", "who");
|
||||
@@ -3892,8 +3897,8 @@ magpie.plugin("library", (ctx) => {
|
||||
return lib.agents.filter((a) => kind === "skills" ? a.skills : a.mcp).map((a) => {
|
||||
const has = items.filter((x) => x.agents?.includes(a.id)).length;
|
||||
const missing = items.filter((x) => can(x, a) && !x.agents?.includes(a.id)).length;
|
||||
return { a, has, missing, hidden: isHidden(a) };
|
||||
}).filter((r) => !r.hidden || r.has || kept?.has(r.a.id));
|
||||
return { a, has, missing, hidden: isHidden(a), gone: !!a.gone };
|
||||
}).filter((r) => !r.hidden && !r.gone || r.has || kept?.has(r.a.id));
|
||||
}
|
||||
|
||||
function openByAgent(kind) {
|
||||
@@ -3908,12 +3913,16 @@ magpie.plugin("library", (ctx) => {
|
||||
const list = el("div", "list lib-list lib-byagent-list");
|
||||
let busy = false;
|
||||
const listed = new Set(byAgentRows(kind).map((r) => r.a.id));
|
||||
const draw = () => list.replaceChildren(...byAgentRows(kind, listed).map(({ a, has, missing, hidden }) => {
|
||||
const draw = () => list.replaceChildren(...byAgentRows(kind, listed).map(({ a, has, missing, hidden: shy, gone }) => {
|
||||
const row = el("div", "row lib-row lib-byagent-row");
|
||||
row.dataset.agent = a.id;
|
||||
const who = el("div", "who");
|
||||
const name = el("div", "name", a.name);
|
||||
if (hidden) name.append(tag(t("Hidden"), "", t("Hidden on the Agents page: it isn't given anything new, and what it has can be taken out here")));
|
||||
// one gone from this computer is listed while it has some, for them
|
||||
// to be taken out, as one hidden is
|
||||
const hidden = shy || gone;
|
||||
if (gone) name.append(tag(t("Not installed here"), "", t("Not installed here: it isn't given anything new, and what it has can be taken out here")));
|
||||
else if (hidden) name.append(tag(t("Hidden"), "", t("Hidden on the Agents page: it isn't given anything new, and what it has can be taken out here")));
|
||||
who.append(name, el("div", "sub", skills ? t("{n} of {m} skills", { n: has, m: items().length }) : t("{n} of {m} servers", { n: has, m: items().length })));
|
||||
const on = button(t("Turn all on"), "action lib-updall lib-agenton", (e, b) => everyFor(a, true, b));
|
||||
on.disabled = busy || hidden || !missing;
|
||||
@@ -4320,7 +4329,7 @@ magpie.plugin("library", (ctx) => {
|
||||
rm.append(svg(GLYPH.trash, 13, 1.4));
|
||||
rm.title = t("Remove");
|
||||
acts.append(rm);
|
||||
row.append(mark(s.icon, GLYPH.skill), who, acts, agentChips(all, s.agents, chipsChange("skills/agents", s.name, "skills", (x) => skillRow(x, all)), { problems: s.problems, via: viaFor(s), all: true, always: alwaysFor(s) }));
|
||||
row.append(mark(s.icon, GLYPH.skill), who, acts, agentChips(withGone(all, s.agents), s.agents, chipsChange("skills/agents", s.name, "skills", (x) => skillRow(x, all)), { problems: s.problems, via: viaFor(s), all: true, always: alwaysFor(s) }));
|
||||
if (picking) return pickRow(row, s.name);
|
||||
row.onclick = () => viewSkill(s);
|
||||
row.title = t("Read {name}'s SKILL.md", { name: s.name });
|
||||
|
||||
@@ -563,6 +563,9 @@ magpie.strings({
|
||||
"Official — from the team that makes it": "官方 — 来自其开发团队",
|
||||
"{n} installs": "{n} 次安装",
|
||||
"No description.": "暂无描述。",
|
||||
"{agent} isn't installed here — click to take it away": "本机没有安装 {agent}——点一下把它移除",
|
||||
"Not installed here": "本机未安装",
|
||||
"Not installed here: it isn't given anything new, and what it has can be taken out here": "本机没有安装:不会再分配新的内容,已有的可以在这里移除",
|
||||
},
|
||||
"zh-TW": {
|
||||
"already in the library: {names}": "資源庫裡已有:{names}",
|
||||
@@ -1126,6 +1129,9 @@ magpie.strings({
|
||||
"Official — from the team that makes it": "官方 — 來自其開發團隊",
|
||||
"{n} installs": "{n} 次安裝",
|
||||
"No description.": "暫無描述。",
|
||||
"{agent} isn't installed here — click to take it away": "本機沒有安裝 {agent}——點一下把它移除",
|
||||
"Not installed here": "本機未安裝",
|
||||
"Not installed here: it isn't given anything new, and what it has can be taken out here": "本機沒有安裝:不會再分配新的內容,已有的可以在這裡移除",
|
||||
},
|
||||
ja: {
|
||||
"Give skills as": "スキルの渡し方",
|
||||
@@ -1689,6 +1695,9 @@ magpie.strings({
|
||||
"{n} installs": "{n} 回インストール",
|
||||
"No description.": "説明はありません。",
|
||||
"It will be removed from the library and the agents it was given to.": "ライブラリと使用中のエージェントから削除されます。",
|
||||
"{agent} isn't installed here — click to take it away": "{agent} はこのコンピューターにインストールされていません — クリックして外します",
|
||||
"Not installed here": "このパソコンに未インストール",
|
||||
"Not installed here: it isn't given anything new, and what it has can be taken out here": "このコンピューターにはインストールされていません:新しいものは割り当てられず、すでにあるものはここで外せます",
|
||||
},
|
||||
de: {
|
||||
"Give skills as": "Skills geben als",
|
||||
@@ -2252,5 +2261,8 @@ magpie.strings({
|
||||
"{n} installs": "{n} Installationen",
|
||||
"No description.": "Keine Beschreibung.",
|
||||
"It will be removed from the library and the agents it was given to.": "Es wird aus der Bibliothek und den Agenten entfernt, denen es zugewiesen wurde.",
|
||||
"{agent} isn't installed here — click to take it away": "{agent} ist hier nicht installiert – klicken, um es zu entfernen",
|
||||
"Not installed here": "Hier nicht installiert",
|
||||
"Not installed here: it isn't given anything new, and what it has can be taken out here": "Hier nicht installiert: Es erhält nichts Neues, und was es hat, kann hier entfernt werden",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// @jiahao_jayden on X: every skill's row had a chip for each agent magpie
|
||||
// knew of, WorkBuddy among them though it wasn't installed (一排有点密恐了).
|
||||
// The library lists an agent gone from this computer (gone: true) only
|
||||
// while it still has something magpie gave it, so that can be taken out:
|
||||
// its chip is on the rows of what it has, lit, and a click takes it away;
|
||||
// it is on no other row, All leaves it out, and By agent lists it as Not
|
||||
// installed with nothing to turn on. Chromium and WebKit, 1100px and
|
||||
// 390px, in en, zh, zh-TW, ja and de. No backend: the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { strings } = require("./strings.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const HOME = "/Users/me";
|
||||
const agent = (id, name, more = {}) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json`, ...more });
|
||||
const local = (name, agents) => ({ name, description: name + " does a thing", kind: "local", agents });
|
||||
// as Read lists them: one gone from here only while it has something
|
||||
const lib = (skills) => ({
|
||||
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
||||
agents: [agent("claude", "Claude Code"), agent("codex", "Codex"),
|
||||
...(skills.some((s) => s.agents.includes("workbuddy")) ? [agent("workbuddy", "WorkBuddy", { gone: true })] : [])],
|
||||
instructions: { agents: [] }, servers: [], skills, foundServers: [], projects: [], foundSkills: [], problems: [],
|
||||
});
|
||||
|
||||
let I18N;
|
||||
function tr(lang, key, vars = {}) {
|
||||
let s = key;
|
||||
if (lang !== "en") {
|
||||
assert.equal(typeof I18N[lang][key], "string", `${lang} has no ${JSON.stringify(key)}`);
|
||||
s = I18N[lang][key];
|
||||
}
|
||||
return s.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m));
|
||||
}
|
||||
|
||||
function server(lang, state, posts) {
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data, status = 200) => route.fulfill({ status, json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light" } });
|
||||
if (url.pathname === "/api/library") return json(lib(state.skills));
|
||||
if (url.pathname.startsWith("/api/library/") && req.method() === "POST" && !url.pathname.endsWith("/reveal")) {
|
||||
const body = req.postDataJSON(), what = url.pathname.replace("/api/library/", "");
|
||||
posts.push({ what, body });
|
||||
if (what === "skills/agents") {
|
||||
state.skills = state.skills.map((s) => (s.name === body.name ? { ...s, agents: [...body.agents].sort() } : s));
|
||||
return json({ ...lib(state.skills), result: { changed: ["claude", "workbuddy"] } });
|
||||
}
|
||||
return json(lib(state.skills));
|
||||
}
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true } });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
const sideways = (page) => page.evaluate(() => {
|
||||
const over = [];
|
||||
const w = document.documentElement.clientWidth;
|
||||
if (document.documentElement.scrollWidth > w) over.push("page " + document.documentElement.scrollWidth);
|
||||
for (const e of document.querySelectorAll("#view-library .lib-skill, #view-library .lib-agents, #modal .lib-editor, #modal .lib-byagent-row")) {
|
||||
const r = e.getBoundingClientRect();
|
||||
if (r.width && (r.right > w + 0.5 || r.left < -0.5)) over.push((e.className || e.tagName) + " " + Math.round(r.left) + "–" + Math.round(r.right));
|
||||
}
|
||||
return over;
|
||||
});
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": an agent not installed is only on the rows of what it still has", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
I18N = strings().I18N;
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const width of [1100, 390]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
await t.test(`${lang} at ${width}px`, async () => {
|
||||
const w = (key, vars) => tr(lang, key, vars);
|
||||
const state = { skills: [local("pdf", ["claude", "workbuddy"]), local("csv", ["claude"]), local("notes", ["claude", "codex"])] };
|
||||
const posts = [], errors = [];
|
||||
const ctx = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "skills"); } catch {} });
|
||||
const page = await ctx.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
page.on("dialog", (d) => { errors.push("a browser dialog: " + d.message()); d.dismiss(); });
|
||||
await page.route("**/*", server(lang, state, posts));
|
||||
await page.goto("http://magpie.test/");
|
||||
await page.locator('button[data-view="library"]').click();
|
||||
const v = page.locator("#view-library");
|
||||
const row = (name) => v.locator(".lib-skill").filter({ has: page.locator(".name", { hasText: new RegExp("^" + name) }) });
|
||||
const chips = (name) => row(name).locator(":scope > .lib-agents > .lib-ag[data-agent]").evaluateAll((cs) => cs.map((c) => c.dataset.agent));
|
||||
await row("notes").waitFor();
|
||||
|
||||
// WorkBuddy is on pdf's row alone, lit, saying it isn't installed
|
||||
assert.deepEqual(await chips("pdf"), ["claude", "codex", "workbuddy"]);
|
||||
assert.deepEqual(await chips("csv"), ["claude", "codex"], "a chip for an agent not installed on a row it has nothing on");
|
||||
assert.deepEqual(await chips("notes"), ["claude", "codex"]);
|
||||
const wb = row("pdf").locator('.lib-ag[data-agent="workbuddy"]');
|
||||
assert.match(await wb.getAttribute("class"), /\bgone\b/);
|
||||
assert.equal(await wb.getAttribute("aria-pressed"), "true");
|
||||
assert.equal(await wb.getAttribute("title"), w("{agent} isn't installed here — click to take it away", { agent: "WorkBuddy" }));
|
||||
// All counts the two installed, not WorkBuddy
|
||||
const all = row("pdf").locator(".lib-ag.all");
|
||||
assert.equal(await all.getAttribute("title"), w("Give it to all {n} agents that can take it", { n: 2 }));
|
||||
assert.deepEqual(await sideways(page), [], "sideways with the rows");
|
||||
|
||||
// By agent: WorkBuddy as Not installed, nothing to turn on, its one
|
||||
// skill to take out
|
||||
const sheet = page.locator("#modal .lib-editor");
|
||||
await v.locator(".lib-byagent").first().click();
|
||||
await sheet.waitFor();
|
||||
const ids = await sheet.locator(".lib-byagent-row").evaluateAll((rs) => rs.map((r) => r.dataset.agent));
|
||||
assert.deepEqual(ids, ["claude", "codex", "workbuddy"]);
|
||||
const wbRow = sheet.locator('.lib-byagent-row[data-agent="workbuddy"]');
|
||||
await wbRow.locator(".name", { hasText: w("Not installed here") }).waitFor();
|
||||
assert.equal(await wbRow.locator(".lib-agenton").isDisabled(), true, "Turn all on for an agent not installed");
|
||||
assert.equal(await wbRow.locator(".lib-agentoff").isDisabled(), false);
|
||||
assert.deepEqual(await sideways(page), [], "sideways with By agent");
|
||||
await sheet.locator(".bar button.primary").click();
|
||||
await sheet.waitFor({ state: "detached" });
|
||||
|
||||
// its chip clicked: pdf is taken from it, the others keep theirs
|
||||
await row("pdf").locator(":scope > .lib-agents").hover();
|
||||
await wb.click();
|
||||
await page.waitForTimeout(300);
|
||||
assert.deepEqual(posts, [{ what: "skills/agents", body: { name: "pdf", agents: ["claude"] } }]);
|
||||
assert.deepEqual(errors, []);
|
||||
await ctx.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -106,6 +106,8 @@ func TestAgentMCPFiles(t *testing.T) {
|
||||
fs: entry{"type": "stdio", "command": "npx", "args": []any{"-y", "@mcp/fs"}, "env": entry{"K": "V"}},
|
||||
web: entry{"type": "http", "url": "https://example.com/mcp", "headers": entry{"Authorization": "Bearer x"}},
|
||||
sse: entry{"type": "sse", "url": "https://example.com/sse"},
|
||||
// on a Mac WorkBuddy is there by its app, not its folder
|
||||
pre: func(t *testing.T, h string) { holdApp(t, h, "WorkBuddy.app", "com.tencent.workbuddy.mac") },
|
||||
},
|
||||
{
|
||||
// CodeBuddy Code reads the first of .mcp.json, mcp.json and
|
||||
|
||||
@@ -24,6 +24,8 @@ func TestAgentsSkillsFolders(t *testing.T) {
|
||||
// alone is gone, #2177, and no target — TestTargetsLeaveGoneAgentsOut)
|
||||
holdCLI(t, h, "hermes")
|
||||
holdCLI(t, h, "cline")
|
||||
// and WorkBuddy's app, which is how a Mac has it
|
||||
holdApp(t, h, "WorkBuddy.app", "com.tencent.workbuddy.mac")
|
||||
want := map[string]string{
|
||||
"kimi": ".agents/skills",
|
||||
"goose": ".agents/skills",
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// holdApp puts a macOS app bundle, its Info.plist saying id, in the sandbox
|
||||
// home's Applications, where a Mac's apps are looked for.
|
||||
func holdApp(t *testing.T, h, name, id string) {
|
||||
t.Helper()
|
||||
write(t, filepath.Join(h, "Applications", name, "Contents", "Info.plist"),
|
||||
`<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict><key>CFBundleIdentifier</key><string>`+id+`</string></dict></plist>`)
|
||||
}
|
||||
|
||||
// @jiahao_jayden on X: the library's rows listed agents that aren't
|
||||
// installed. One gone from here (uninstalled: its CLI gone, its folder
|
||||
// left, #2177) is listed only while it still has what magpie gave it, on
|
||||
// the rows of what it has, so that can be unticked and taken out of its
|
||||
// folder; a sync gives it nothing new, and once it has nothing it isn't
|
||||
// listed at all.
|
||||
func TestGoneAgentListedToTakeOut(t *testing.T) {
|
||||
h := sandbox(t)
|
||||
write(t, filepath.Join(h, ".hermes/config.yaml"), "")
|
||||
holdCLI(t, h, "hermes")
|
||||
src := filepath.Join(h, "src/skills")
|
||||
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
|
||||
skill(t, filepath.Join(src, "csv"), "csv", "Read CSVs")
|
||||
ok(t)(InstallSkills(src, []string{"pdf", "csv"}, []string{"claude", "hermes"}))
|
||||
pdf, csv := filepath.Join(h, ".hermes/skills/pdf"), filepath.Join(h, ".hermes/skills/csv")
|
||||
if !ours(pdf, "pdf") || !ours(csv, "csv") {
|
||||
t.Fatal("hermes wasn't given the skills")
|
||||
}
|
||||
cfg := filepath.Join(h, ".hermes/config.yaml")
|
||||
ok(t)(SaveServer("", Server{Name: "fs", Transport: "stdio", Command: "npx", Args: []string{"-y", "@mcp/fs"}, Agents: []string{"claude", "hermes"}}))
|
||||
if !strings.Contains(read(t, cfg), "@mcp/fs") {
|
||||
t.Fatalf("hermes wasn't given the server:\n%s", read(t, cfg))
|
||||
}
|
||||
|
||||
// uninstalled: its CLI gone, its folder left
|
||||
os.Remove(filepath.Join(h, "bin/hermes"))
|
||||
os.Remove(filepath.Join(h, "bin/hermes.exe"))
|
||||
if targetByID("hermes") != nil {
|
||||
t.Fatal("hermes is still a target without its CLI")
|
||||
}
|
||||
gone := func() *AgentView {
|
||||
t.Helper()
|
||||
v, err := Read(nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i, a := range v.Agents {
|
||||
if a.ID == "hermes" {
|
||||
return &v.Agents[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if a := gone(); a == nil || !a.Gone || a.Skills == "" || a.MCP == "" {
|
||||
t.Fatalf("hermes, holding a skill and a server, isn't listed as gone: %+v", a)
|
||||
}
|
||||
// claude is no gone agent
|
||||
if v, _ := Read(nil); !slices.ContainsFunc(v.Agents, func(a AgentView) bool { return a.ID == "claude" && !a.Gone }) {
|
||||
t.Errorf("claude: %+v", v.Agents)
|
||||
}
|
||||
|
||||
// a sync gives it nothing new: a link taken out by hand isn't made again
|
||||
os.Remove(csv)
|
||||
ok(t)(Sync())
|
||||
if _, err := os.Lstat(csv); !os.IsNotExist(err) {
|
||||
t.Error("a sync gave the gone hermes a skill again")
|
||||
}
|
||||
|
||||
// unticked, the skill and the server come out of its folder
|
||||
ok(t)(SkillAgents("pdf", []string{"claude"}))
|
||||
if _, err := os.Lstat(pdf); !os.IsNotExist(err) {
|
||||
t.Errorf("pdf unticked is still in the gone hermes's skills: %v", err)
|
||||
}
|
||||
if !ours(filepath.Join(h, ".claude/skills/pdf"), "pdf") {
|
||||
t.Error("claude lost pdf")
|
||||
}
|
||||
ok(t)(SkillAgents("csv", []string{"claude"}))
|
||||
ok(t)(ServerAgents("fs", []string{"claude"}))
|
||||
if strings.Contains(read(t, cfg), "@mcp/fs") {
|
||||
t.Errorf("the server unticked is still in the gone hermes's config:\n%s", read(t, cfg))
|
||||
}
|
||||
// with nothing left it isn't listed
|
||||
if a := gone(); a != nil {
|
||||
t.Errorf("hermes, holding nothing, is still listed: %+v", a)
|
||||
}
|
||||
}
|
||||
@@ -635,7 +635,9 @@ func (l *Library) syncHooks(t *Target, b *backups, res *Result) {
|
||||
add := map[string][]json.RawMessage{}
|
||||
var added []HookEntry
|
||||
for _, w := range ws {
|
||||
if w.done {
|
||||
// an agent gone from here is given nothing new; what it has stays
|
||||
// its until unticked
|
||||
if w.done || t.Gone {
|
||||
continue
|
||||
}
|
||||
// the same entry of the user's own already runs: it isn't written
|
||||
|
||||
@@ -516,6 +516,14 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
|
||||
if !slices.Contains(s.Agents, id) {
|
||||
continue
|
||||
}
|
||||
// an agent gone from here is given nothing: what it has still
|
||||
// stays its, until unticked
|
||||
if t.Gone {
|
||||
if slices.Contains(a.Skills, s.Name) && !slices.Contains(mine, s.Name) {
|
||||
mine = append(mine, s.Name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
p := filepath.Join(t.Skills, s.Name)
|
||||
if l.blockedSkills[realDir(p)] {
|
||||
if !slices.Contains(mine, s.Name) {
|
||||
|
||||
+43
-10
@@ -63,7 +63,8 @@ func (l *Library) sync() *Result {
|
||||
if b == nil {
|
||||
b = newBackups()
|
||||
}
|
||||
for _, step := range syncSteps(Targets(), b, res) {
|
||||
all := Targets()
|
||||
for _, step := range syncSteps(all, l.held(all), b, res) {
|
||||
step(l)
|
||||
}
|
||||
res.Backup = b.dir
|
||||
@@ -73,8 +74,10 @@ func (l *Library) sync() *Result {
|
||||
return res
|
||||
}
|
||||
|
||||
// syncSteps are what a sync does, one agent's part at a time, in order.
|
||||
func syncSteps(all []*Target, b *backups, res *Result) []func(*Library) {
|
||||
// syncSteps are what a sync does, one agent's part at a time, in order. The
|
||||
// agents gone from here that still have what magpie gave them (held) only
|
||||
// have what was unticked taken out, after the rest.
|
||||
func syncSteps(all, gone []*Target, b *backups, res *Result) []func(*Library) {
|
||||
var steps []func(*Library)
|
||||
for _, t := range all {
|
||||
steps = append(steps, func(l *Library) {
|
||||
@@ -84,8 +87,16 @@ func syncSteps(all []*Target, b *backups, res *Result) []func(*Library) {
|
||||
})
|
||||
}
|
||||
// an edit made in an agent's copy of a skill goes to the library first,
|
||||
// for the others to get rather than be undone (takeEdits)
|
||||
steps = append(steps, func(l *Library) { l.takeEdits(all, res) })
|
||||
// for the others to get rather than be undone (takeEdits); one in a
|
||||
// gone agent's copy too, before that copy is taken out
|
||||
steps = append(steps, func(l *Library) { l.takeEdits(append(slices.Clone(all), gone...), res) })
|
||||
for _, t := range gone {
|
||||
steps = append(steps, func(l *Library) {
|
||||
l.syncMCP(t, b, res)
|
||||
l.syncHooks(t, b, res)
|
||||
l.syncSkills(t, res, all)
|
||||
})
|
||||
}
|
||||
// ~/.agents/skills first: an agent that reads it too gets no second
|
||||
// link to what is there already
|
||||
shared := realDir(sharedSkillsDir())
|
||||
@@ -113,7 +124,7 @@ func syncSteps(all []*Target, b *backups, res *Result) []func(*Library) {
|
||||
func Sync() (*Result, error) {
|
||||
res := &Result{Changed: []string{}, Problems: []Problem{}}
|
||||
b := newBackups()
|
||||
var all []*Target
|
||||
var all, gone []*Target
|
||||
// what the step before learnt of the skills (hashes, copies found
|
||||
// untouched), kept while nothing else held the lock between
|
||||
var memo *Library
|
||||
@@ -136,10 +147,10 @@ func Sync() (*Result, error) {
|
||||
return nil
|
||||
}
|
||||
// the agents are found under the lock, as a change finds them
|
||||
if err := step(func(*Library) { all = Targets() }); err != nil {
|
||||
if err := step(func(l *Library) { all = Targets(); gone = l.held(all) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, f := range syncSteps(all, b, res) {
|
||||
for _, f := range syncSteps(all, gone, b, res) {
|
||||
if err := step(f); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -161,7 +172,7 @@ func (l *Library) syncMCP(t *Target, b *backups, res *Result) {
|
||||
a := l.applied(id)
|
||||
// an agent given no server, with none of magpie's in it, isn't read:
|
||||
// a file of its that can't be read is nothing the library did
|
||||
if len(a.MCP) == 0 && len(a.ToolRules) == 0 && !slices.ContainsFunc(l.MCP, func(s *Server) bool { return slices.Contains(s.Agents, id) }) {
|
||||
if len(a.MCP) == 0 && len(a.ToolRules) == 0 && (t.Gone || !slices.ContainsFunc(l.MCP, func(s *Server) bool { return slices.Contains(s.Agents, id) })) {
|
||||
return
|
||||
}
|
||||
how := toolsOffOf(t)
|
||||
@@ -200,6 +211,15 @@ func (l *Library) syncMCP(t *Target, b *backups, res *Result) {
|
||||
if !slices.Contains(s.Agents, id) {
|
||||
continue
|
||||
}
|
||||
// an agent gone from here is given nothing: what it has still
|
||||
// stays its, until unticked
|
||||
if t.Gone {
|
||||
if slices.Contains(a.MCP, s.Name) {
|
||||
mine = append(mine, s.Name)
|
||||
toolsOff[s.Name] = a.ToolsOff[s.Name]
|
||||
}
|
||||
continue
|
||||
}
|
||||
s := through(s, base)
|
||||
if err := t.MCP.supports(s); err != nil {
|
||||
res.fail(id, "mcp:"+s.Name, err)
|
||||
@@ -284,6 +304,9 @@ type AgentView struct {
|
||||
How string `json:"how,omitempty"`
|
||||
HowOwn bool `json:"howOwn,omitempty"`
|
||||
MustCopy bool `json:"mustCopy,omitempty"`
|
||||
// Gone: not installed here any more, and listed only for what magpie
|
||||
// gave it to be taken out (held); it is given nothing new
|
||||
Gone bool `json:"gone,omitempty"`
|
||||
}
|
||||
|
||||
// ServerView is a library server, and what each agent it's on made of it.
|
||||
@@ -402,6 +425,16 @@ func readView(problems []Problem, glance bool) (*View, error) {
|
||||
}
|
||||
v.Agents = append(v.Agents, av)
|
||||
}
|
||||
// an agent gone from here that still has what magpie gave it: listed on
|
||||
// the rows of what it has, for that to be taken out (held)
|
||||
gone := l.held(targets)
|
||||
for _, t := range gone {
|
||||
av := AgentView{ID: t.Agent.ID, Name: t.Agent.Name, Icon: t.Agent.Icon, Skills: t.Skills, Gone: true}
|
||||
if t.MCP != nil {
|
||||
av.MCP = t.MCP.Path
|
||||
}
|
||||
v.Agents = append(v.Agents, av)
|
||||
}
|
||||
of := func(what string) map[string]string {
|
||||
m := map[string]string{}
|
||||
for _, p := range problems {
|
||||
@@ -438,7 +471,7 @@ func readView(problems []Problem, glance bool) (*View, error) {
|
||||
}
|
||||
v.Servers = append(v.Servers, sv)
|
||||
}
|
||||
v.Hooks, v.HookAgents = l.hooksView(targets, of)
|
||||
v.Hooks, v.HookAgents = l.hooksView(append(slices.Clone(targets), gone...), of)
|
||||
tr := &tracer{}
|
||||
for _, s := range l.Skills {
|
||||
sv := SkillView{Name: s.Name, Agents: append([]string{}, s.Agents...), Icon: skillIcon(s), Problems: of("skill:" + s.Name), Repo: tr.repoOf(s)}
|
||||
|
||||
@@ -47,6 +47,10 @@ type Target struct {
|
||||
// Settings is Claude Code's settings.json, whose permissions.deny
|
||||
// leaves out the tools of a server turned off (mcp_tools_off.go)
|
||||
Settings string
|
||||
// Gone is an agent no longer installed here that still has what magpie
|
||||
// gave it (held): a sync only takes things out of it, as they are
|
||||
// unticked, and gives it nothing.
|
||||
Gone bool
|
||||
}
|
||||
|
||||
func home() string { h, _ := os.UserHomeDir(); return h }
|
||||
@@ -691,6 +695,39 @@ func targets(gone bool) []*Target {
|
||||
return out
|
||||
}
|
||||
|
||||
// held are the agents not among have (Targets) — uninstalled, or gone for
|
||||
// their CLI — that the library still gives something, or that hold a skill,
|
||||
// server or hook magpie put there: each is listed on the rows of what it
|
||||
// has, for that to be unticked and taken out of it, and on no other row
|
||||
// (@jiahao_jayden on X: an agent that isn't installed was on every row). A
|
||||
// sync gives them nothing new (Gone).
|
||||
func (l *Library) held(have []*Target) []*Target {
|
||||
in := map[string]bool{}
|
||||
for _, t := range have {
|
||||
in[t.Agent.ID] = true
|
||||
}
|
||||
has := func(id string) bool {
|
||||
if a := l.Applied[id]; a != nil && (len(a.Skills) > 0 || len(a.MCP) > 0 || len(a.Hooks) > 0) {
|
||||
return true
|
||||
}
|
||||
return slices.ContainsFunc(l.Skills, func(s *Skill) bool { return slices.Contains(s.Agents, id) }) ||
|
||||
slices.ContainsFunc(l.MCP, func(s *Server) bool { return slices.Contains(s.Agents, id) }) ||
|
||||
slices.ContainsFunc(l.Hooks, func(h *Hook) bool { return slices.Contains(h.Agents, id) })
|
||||
}
|
||||
var out []*Target
|
||||
for _, a := range append(apps(), agent.All()...) {
|
||||
if in[a.ID] || a.WSL != "" || !has(a.ID) {
|
||||
continue
|
||||
}
|
||||
in[a.ID] = true
|
||||
if t := targetOf(a); t != nil && t.open() {
|
||||
t.Gone = true
|
||||
out = append(out, t)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// readsShared are the agents that read ~/.agents/skills as well as their
|
||||
// own folder (each one's docs or source).
|
||||
var readsShared = []string{"codex", "gemini", "opencode", "deveco", "crush", "dsh", "commandcode", "devin", "droid", "cline", "grok", "grok-app", "fx", "alma"}
|
||||
|
||||
Reference in New Issue
Block a user