スライム on Discord (#help, 10-22): taste-skills took some of its skills
out, Update all reported each of them as a failure, and the only way
out was to delete them one by one.
An update or a check that reads the source whole and finds the skill's
folder (or its SKILL.md) gone now calls it removed upstream, not a
failure. GitHub tarballs and other git repositories both work this way.
- UpdateSkill returns *GoneError.
- UpdateSkills and UpdateSomeSkills list it in Result.Gone, not
Unupdated.
- A check gives status "gone".
- Each marks Skill.Gone. The mark is cleared when a check or an update
finds the skill there again.
- A fetch that failed, a skill left out of a fetch as too big, and a
folder that can't be read stay unknown, never gone (goneFrom).
Nothing is deleted by itself. RemoveGoneSkills takes the named skills
out, or every marked one when none are named, through RemoveSkills, so
the folders go to the backups. A skill found in its source again is
kept and said so.
- GUI: a "Removed upstream" tag replaces Update available and the
update icon. Update all says gone skills apart from failures. "Clean
up N" sits in the group heading, or in the bar when there is one
group, and opens a sheet naming each skill. One changed here carries
"Changed here". Strings are in en, zh, zh-TW, ja and de.
- CLI: `magpie library skill rm --gone [--yes]` asks at a terminal and
refuses without --yes otherwise. It names the ones changed here.
update and status print the hint.
- TUI: the row says "removed from <repo> · d takes it out".
- API: POST /api/library/skills/remove-gone {names}.
- Docs: the Skill updates row and Verification in
docs/subsystems/library.md.
Record for this push: 13 commits on origin/main ca4a1cde0, head tree
539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go
run and vet were at tree d6393dfc8, the same Go code as this head: only
app.js comments (cut under the core script budget) and one ja string
changed after it.
- gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux
go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./..., through tee, one suite on the machine:
68 packages ok. The one red was internal/gui's
TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew
app.js under the stack. The autoscroll commit's own comments were cut
(to 1,334,629) rather than the budget raised, and go test -count=1
./internal/gui is ok at this head (113s). Packages the run took from
Go's test cache had the same inputs.
- GUI: the 18 files this stack touches or names, both engines,
202 of 204 pass (tree 068acf128, this push less the last commit). The
two reds: gui-ja, red on main since c2636b7b5 and fixed by this push's
last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's
chromium "several accounts" (#2163, red on main the same way).
- skill-gone passes, chromium and webkit, en and zh, 860 and 400px.
- internal/library, internal/cli and internal/tui ok, the Gone tests and
TestLibrarySkillRm among them.
- The rebase onto main met c2636b7b5's Verification line in library.md;
both sides' tests are kept in it.
The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on
0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run
alone at the stack and at origin/main 8278fd9b0. Eight are red the same
way on main: plugin-card-update (#3079), quota-count-wrap and
quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide
(#2276), usage-checkin (#3091), usage-fold's chromium "several
accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both
and were red only under that run's load (50 to 335): currency #3101,
plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564,
routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804,
routing-wb-restricted #1905, sessions-folder-delete #2218,
sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack
#3296.
Broken by hand, each red, then restored:
- prepare not returning GoneError
- apply not clearing Gone
- leftOutAt ignored
- every Stat error read as absent
- the git check not saying gone
- RemoveGoneSkills taking a skill that isn't marked
Not tried:
- the real taste-skills repo over the network
- the Windows box
- a skill CC Switch installed (Origin, adopt path), which still reports
as a failure
- a GitHub check with a known commit, which keeps an existing gone
mark but only marks gone after an update
154 lines
4.3 KiB
Go
154 lines
4.3 KiB
Go
package library
|
|
|
|
// A skill its source no longer has (スライム on Discord): the repository
|
|
// it came from was read, and its folder isn't there any more. An update
|
|
// then has nothing to fetch, which is no failure of the update: the skill
|
|
// is marked removed from its source (Skill.Gone), for the page to say so
|
|
// and offer to take out every such skill of a source at once. Nothing is
|
|
// taken out by itself, as the user may keep using it. Only a source read
|
|
// whole tells: a fetch that failed, or a skill left out of a fetch as too
|
|
// big, says nothing of whether it is still there.
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
// GoneError is a skill its source was read without: it was removed there.
|
|
type GoneError struct {
|
|
Name string
|
|
Source string // the repository
|
|
}
|
|
|
|
func (e *GoneError) Error() string {
|
|
return fmt.Sprintf("%s has no %s any more: it was removed from there", e.Source, e.Name)
|
|
}
|
|
|
|
// goneFrom is whether a fetched source folder, tmp, lacks the skill at
|
|
// path: neither the folder nor its SKILL.md is there. A skill the fetch
|
|
// left out as too big is there, only not fetched; a folder that can't be
|
|
// read is unknown, not gone.
|
|
func goneFrom(tmp, path string) bool {
|
|
if leftOutAt(tmp, path) {
|
|
return false
|
|
}
|
|
dir := filepath.Join(tmp, filepath.FromSlash(path))
|
|
fi, err := os.Stat(dir)
|
|
if err != nil {
|
|
return absent(err)
|
|
}
|
|
if !fi.IsDir() {
|
|
return true // a file stands where the skill's folder was
|
|
}
|
|
_, err = os.Stat(filepath.Join(dir, "SKILL.md"))
|
|
return err != nil && absent(err)
|
|
}
|
|
|
|
// absent is whether err says a path isn't there, rather than that it
|
|
// couldn't be read.
|
|
func absent(err error) bool {
|
|
return errors.Is(err, fs.ErrNotExist) || errors.Is(err, syscall.ENOTDIR)
|
|
}
|
|
|
|
// leftOutAt is whether the fetch into dir left out the skill at path, or
|
|
// one inside it, as too big; unlike tookLeftOut it forgets nothing.
|
|
func leftOutAt(dir, path string) bool {
|
|
leftOut.Lock()
|
|
defer leftOut.Unlock()
|
|
for _, l := range leftOut.m[dir] {
|
|
if path == "" || l.Path == path || len(l.Path) > len(path) && l.Path[:len(path)+1] == path+"/" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// markGone records which skills their sources were found without, and
|
|
// which were found there again.
|
|
func markGone(gone, there []string) {
|
|
if len(gone) == 0 && len(there) == 0 {
|
|
return
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
l, err := load()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if l.setGone(gone, there) {
|
|
_ = l.save()
|
|
}
|
|
}
|
|
|
|
// setGone is markGone on a library already loaded; it says whether
|
|
// anything changed.
|
|
func (l *Library) setGone(gone, there []string) bool {
|
|
now := time.Now().UTC().Format(time.RFC3339)
|
|
changed := false
|
|
for _, s := range l.Skills {
|
|
switch {
|
|
case slices.Contains(gone, s.Name) && s.Gone == "":
|
|
s.Gone, changed = now, true
|
|
case slices.Contains(there, s.Name) && s.Gone != "":
|
|
s.Gone, changed = "", true
|
|
}
|
|
}
|
|
return changed
|
|
}
|
|
|
|
// goneCheck is the check a skill found removed from its source keeps
|
|
// till it is updated, installed again or removed.
|
|
func goneCheck(e *GoneError) SkillCheck {
|
|
return SkillCheck{Name: e.Name, Status: "gone", Error: e.Error()}
|
|
}
|
|
|
|
// RemoveGoneSkills takes out of the library, as RemoveSkills does, the
|
|
// skills named that their sources no longer have; with none named, every
|
|
// such skill. One found in its source again since is left, and said in
|
|
// Unremoved.
|
|
func RemoveGoneSkills(names []string) (*Result, error) {
|
|
mu.Lock()
|
|
l, err := load()
|
|
mu.Unlock()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var take []string
|
|
var left []Problem
|
|
if names == nil {
|
|
for _, s := range l.Skills {
|
|
if s.Gone != "" {
|
|
take = append(take, s.Name)
|
|
}
|
|
}
|
|
} else {
|
|
for _, name := range slices.Compact(slices.Sorted(slices.Values(names))) {
|
|
switch s := l.skill(name); {
|
|
case s == nil:
|
|
left = append(left, Problem{What: "skill:" + name, Error: "no skill called " + name})
|
|
case s.Gone == "":
|
|
left = append(left, Problem{What: "skill:" + name, Error: name + " is in its source again; it's kept"})
|
|
default:
|
|
take = append(take, name)
|
|
}
|
|
}
|
|
}
|
|
if len(take) == 0 {
|
|
if len(left) > 0 {
|
|
return nil, errors.New(left[0].Error)
|
|
}
|
|
return nil, fmt.Errorf("no skill is removed from its source")
|
|
}
|
|
res, err := RemoveSkills(take)
|
|
if res != nil {
|
|
res.Unremoved = append(res.Unremoved, left...)
|
|
}
|
|
return res, err
|
|
}
|