4db65681c carries this commit's first message by mistake (another session's amend read it from a shared file); it holds none of this change, which is here.
tnt1223 on Discord: Library › Skills listed 16 skills for
https://github.com/asdfgh1445/ctf-super-hub, which has 35 (one folder each
at the top, 35 SKILL.md in its recursive tree, not truncated).
Cause: the listing found all 35, but nameFor made each SKILL.md's `name`
fit for a file name by dropping everything outside ASCII. "CTF•密码学" and
ten more became "CTF", "Strix•RCE 测试" and nine more "Strix", "头脑风暴"
nothing, and unhiddenFirst lists skills of the same name once, so 35
became 16. Not a depth limit, cap, pagination or truncated tree: the probe
downloads the tarball and walks it; a truncated tree and GitHub's rate
limit are already said (skilltree.go, fetch).
Fix: a declared name that would lose a letter or digit (another script)
or comes out empty goes by its folder's name, which a repository keeps
apart. An ASCII name goes as before ("My Skill" is still My-Skill), so a
skill installed from one is still the library's. A skill at a
repository's top now falls back to the repository's name (srcFolder),
not the temporary download folder; candidates takes that name from each
caller (probe, Group again, CC Switch origin, new-skill check).
Tests: TestSkillsNamedInAnotherScriptAllListed probes and installs from a
fake of the repository built from its real tree (35 folders, front matter
names as written at 7715719); TestSkillNameFallsBackToFolderOnlyWhenLettersAreLost
and TestSkillAtTheTopNamedInAnotherScript cover the rule and the top
folder. No network.
Run:
- mote: go vet ./internal/library; GOOS=linux and GOOS=windows go vet
-tags nogui ./internal/library; gofmt -l internal docs (empty);
go test ./internal/library -run 'TestSkillsNamedInAnotherScript|
TestSkillNameFallsBack|TestSkillAtTheTop|TestRepoWithAPlugin|Probe|
CCSwitch|Regroup|NewSkill|From' -count=1: ok.
- wsl-run (magpie-desktop): go test -tags nogui ./internal/library
-timeout 45m -count=1: ok 94.9s.
- Live, sandbox HOME (the package's TestMain/testenv), a throwaway test
calling ProbeSkills("https://github.com/asdfgh1445/ctf-super-hub")
against the real GitHub: 35 candidates, each named by its folder,
nothing left out. Not committed.
Broken by hand: nameFor using the declared name whenever it isn't empty
(the old rule): TestSkillsNamedInAnotherScriptAllListed lists 16 with
names CTF/Strix/..., and the rule test fails on "CTF•密码学" and
"Café notes". Restored, green.
Not tried: the full ./... suite (mote at load ~350 from other runs; only
internal/library changed); the GUI suite (no app.js change); Windows test
run; installing the real repository's skills into a real agent. Not
changed: two different skills declaring the same ASCII name in folders of
different names are still listed once, as copies of one skill are
(unhiddenFirst).
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package library
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// ccSwitchOrigin is where on GitHub CC Switch got a skill the library has
|
|
// from CC Switch's folder — linked to there, or a copy CC Switch gave an
|
|
// agent that was taken in — so that it can be updated from GitHub like one
|
|
// installed here. CC Switch's own folder is only ever read.
|
|
func ccSwitchOrigin(s *Skill) (Source, bool) {
|
|
dir := filepath.Join(provider.CCSwitchSkillsDir(), s.Name)
|
|
switch {
|
|
case s.Source == nil:
|
|
if _, err := os.Stat(filepath.Join(dir, "SKILL.md")); err != nil {
|
|
return Source{}, false
|
|
}
|
|
case s.Source.Kind == "folder":
|
|
d := realDir(s.Source.Dir)
|
|
if realDir(filepath.Dir(d)) != realDir(provider.CCSwitchSkillsDir()) {
|
|
return Source{}, false
|
|
}
|
|
dir = d
|
|
default:
|
|
return Source{}, false
|
|
}
|
|
repo, ref, ok := provider.CCSwitchSkillOrigin(filepath.Base(dir))
|
|
if !ok || !repoRe.MatchString(repo) {
|
|
return Source{}, false
|
|
}
|
|
return Source{Kind: "github", Repo: repo, Ref: ref, Path: filepath.Base(dir)}, true
|
|
}
|
|
|
|
// origin finds the skill in the repository fetched for it: the folder
|
|
// named as CC Switch named it, or the skill of that name.
|
|
func origin(root string, src Source, name string) (string, bool) {
|
|
for _, c := range candidates(root, "", srcFolder(src)) {
|
|
if lastPart(c.Path) == src.Path || c.Name == name {
|
|
return c.Path, true
|
|
}
|
|
}
|
|
return "", false
|
|
}
|