Removing a skill always moved its folder to ~/.magpie/backups/<time>/, and backups that hold skills are never pruned, so they piled up. The sheet that asks first now has one tick under what it says, "Keep a copy in magpie's backups", ticked unless the reader unticked it last time (localStorage magpie.libSkillBackup). Unticked, the sheet says the folder is deleted and Remove posts noBackup: true. The default is unchanged. What is deleted is only magpie's own folder for the skill, or an agent's own skill folder. Never deleted, either way: - a folder a library skill links to (~/.agents/skills or anywhere else): only the link goes, and there's no tick on its sheet; - an entry in ~/.agents/skills, which other tools read too: it still goes to the backups (inSharedDir), and the sheet has no tick for it; - a skill brought in from the agents: it still goes back to them; - a link inside a skill's folder: RemoveAll takes the link, not its target. Every path that removes skills: - GUI: one skill, Remove all / Remove n, Remove gone, an agent's own skill and several of them (skills/remove, remove-all, remove-gone, remove-found, remove-found-some take noBackup); - CLI: magpie library skill rm <name> --no-backup, and --no-backup on rm --all and rm --gone, whose prompt says so; - TUI: d asks, then D deletes with no backup (d d still keeps a copy); the first d's flash says so, on rows with a folder to delete. library: RemoveSkillsHow, RemoveFoundSkillsHow, RemoveGoneSkillsHow (keep bool); RemoveSkill(s) and RemoveFoundSkill(s) keep a copy as before. The sheets with the tick say they hold nothing to lose (modal.dirty false): toggling it made Cancel ask to discard changes. A page reload with such a sheet open still reads the form as changed (beforeunload reads the core's modalFormDirty); not changed here. Existing backups stay where they are, in ~/.magpie/backups/<time>/skills and <time>/<agent>/skills. Nothing clears them; the Library's Backups button opens the folder. docs/subsystems/library.md says so. Run (mote, this tree at base 9494a38b4; rebased onto848e3b1b2, whose two commits since touch only internal/gateway): - new tests: TestRemoveSkillWithoutBackup, TestRemoveFoundSkillWithout- Backup (library), TestLibrarySkillRmNoBackup (cli), TestLibraryDeleteWithoutBackup (tui): ok. - broken by hand: with keep forced true in RemoveSkillsHow and RemoveFoundSkillsHow, all four are red (folders found in the backups); with the inSharedDir guard taken out, TestRemoveFoundSkillWithoutBackup is red (the shared entry deleted, not backed up). - go test ./internal/library ./internal/cli ./internal/tui ./internal/gui -timeout 45m: library, cli, tui ok. gui: TestBuiltinsTranslated (#7257) and TestSettingsSaveKeepsWhatItDoesNotSend (#7240) red, the same at origin/main9494a38b4without this change. - gofmt -l: nothing. GOOS=linux go vet -tags nogui and GOOS=windows go vet of those four packages: ok. - GUI, chromium and webkit: skill-remove-nobackup (new: en, zh, zh-TW, ja, de at 980 and 440px; tick, its text, the choice remembered, the post, no tick for linked or shared skills, nothing sideways), i18n-keys, i18n-en-no-cjk and the 27 files that remove skills or read these sheets' lines. Red: the new file's Cancel (the dirty-form ask above, fixed and green after), and api-key-theme (#6444), found-skill-pick-remove at 420px (#5013), saved-signedout-remove (#6666): those 18 the same at origin/main9494a38b4. Not run: the full go test ./... and the whole GUI suite. mote and mica were both taken by other sessions' full suites for over an hour. No guard test outside the packages run reads the files changed (grep for docs/subsystems/library.md and plugins/library). Not tried in the real app or on Windows or Linux; a Windows junction to a skill folder goes through the same linked() branch as on macOS.
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/library"
|
|
)
|
|
|
|
// @Eternalfate__ on X: magpie library skill rm <name> --no-backup deletes
|
|
// the library's own folder with no copy in the backups; without the flag a
|
|
// copy is kept as ever; --all --no-backup --yes the same for every skill.
|
|
func TestLibrarySkillRmNoBackup(t *testing.T) {
|
|
h := t.TempDir()
|
|
for k, v := range map[string]string{"HOME": h, "USERPROFILE": h, "XDG_CONFIG_HOME": filepath.Join(h, ".config"), "CLAUDE_CONFIG_DIR": "", "CODEX_HOME": "", "APPDATA": "", "LOCALAPPDATA": ""} {
|
|
t.Setenv(k, v)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(h, ".claude"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(h, ".claude/settings.json"), []byte("{}"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, n := range []string{"a", "b", "c", "d"} {
|
|
if _, err := library.CreateSkill(n, "A skill", []string{"claude"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
kept := func(name string) int {
|
|
m, _ := filepath.Glob(filepath.Join(library.BackupDir(), "*", "skills", name))
|
|
return len(m)
|
|
}
|
|
if err := libraryCmd([]string{"library", "skill", "rm", "a", "--no-backup"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := libraryCmd([]string{"library", "skill", "rm", "b"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if kept("a") != 0 || kept("b") != 1 {
|
|
t.Errorf("a kept %d (want 0), b kept %d (want 1)", kept("a"), kept("b"))
|
|
}
|
|
if err := libraryCmd([]string{"library", "skill", "rm", "c", "--nope"}); err == nil {
|
|
t.Error("an unknown flag was taken")
|
|
}
|
|
if err := libraryCmd([]string{"library", "skill", "rm", "--all", "--no-backup", "--yes"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := library.Read(nil); len(v.Skills) != 0 {
|
|
t.Errorf("left: %d", len(v.Skills))
|
|
}
|
|
if kept("c") != 0 || kept("d") != 0 {
|
|
t.Errorf("--all --no-backup kept c %d, d %d", kept("c"), kept("d"))
|
|
}
|
|
}
|