biubiu8802 (X, 2119602075864903924) downloaded a skill from GitHub and put it in the Library from its folder, so it had nothing to update from and no way to link it to GitHub. Installing it from its GitHub link now links the two, the way an update of a CC Switch skill already does: the library's skill by that name takes GitHub's files and GitHub as its source. A check and an update cover it from then on, and the agents' links keep pointing at it. When its own files aren't GitHub's, they go to the backups like UpdateSkill's replace does, and the result says so. A folder of the user's it was linked to stays as it is. followsHere (skill_link.go) decides it. It links only a skill with no remote source that wasn't renamed and is that skill: it traces to this repository (CC Switch, the skills CLI's lock, a git checkout, From), or it traces nowhere and its SKILL.md has the same description as GitHub's, as an older download of it does. One traced to another repository, or an untraced one that describes something else (mora1n's case, TestInstallSetPutsAnotherByTheSameNameBeside), still goes in beside it (skill_beside.go). A had skill with the same files and no source is bound to the GitHub source it was found in, so a later install of another repository's skill by that name goes beside it, not over it (TestSameFilesByNameAreHad). The probe marks such a candidate links:true. The GUI's Add list tags it "links to GitHub" with a tooltip, and the report names "updates from GitHub now" and "files of their own kept with the backups". The TUI's probe list and result line say the same. The new strings are in zh, zh-TW, ja and de. Run on mote (macOS), on64ecd0f69, then rebased on8a58c0e30, whose new commits touch none of internal/library, the TUI's library or the library page: - gofmt -l clean; go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=linux go build -tags nogui ./..., GOOS=windows go build ./... all ok - go test ./internal/library/... ok at this tree; ./internal/tui/..., ./internal/cli/... and ./internal/gui/ ok at the tree before the description check (that change touches internal/library only) - GUI (chromium + webkit, 5 languages, wide and narrow): skill-install-link (new), skill-install-beside, skill-install-skip, skill-install-agents-all, skill-git-source, skill-too-big, provider-discovery, i18n-en-no-cjk pass. i18n-keys' "a plugin's words are its own" is red on main for three strings this change doesn't touch, already filed: #5332/#5327 ("View routing"), #5482 ("Use the library's"), #5426 ("No session ID"). Broken by hand: without the description check (the first version), TestInstallSetPutsAnotherByTheSameNameBeside is red (caveman taken over). followsHere returning false always turns TestFolderSkillFollowsGitHub red (probed As:pdf-pro-biubiu) and TestOwnSkillFollowsGitHubKeepsItsFiles red (linked [] kept []). Not run: the full go test ./... suite. mote's suite lock had a queue waiting up to 16h, so this change ran the packages it touches. No real GitHub install either: the tests use a fake tarball server. Not tried on Windows or Linux. The market's had-check (haveSkill) is unchanged: a market skill with a folder copy by that name still counts as had.
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
package library
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// A skill the library has from a folder of the user's, or took in from an
|
|
// agent's folder, has nothing to be updated from. Many of them came from
|
|
// GitHub to begin with: downloaded from there and brought into the
|
|
// library (biubiu8802 on X, wishing it could follow GitHub). Installing
|
|
// that skill from GitHub links the two, as an update of one CC Switch
|
|
// installed does (ccswitch.go): the library's skill by that name takes
|
|
// GitHub's files and GitHub as its source, so a check and an update cover
|
|
// it from then on, and the agents' links to it go on pointing at it. Its
|
|
// own files, when they aren't GitHub's to the file, go to the backups, as
|
|
// an update that replaces an edited skill keeps it (UpdateSkill); a folder
|
|
// of the user's it was linked to is left as it is, and only the library's
|
|
// link to it goes.
|
|
|
|
// followsHere is whether installing from src the skill fetched at from
|
|
// links the library's skill s, which has its name, to it. It must be that
|
|
// skill: traced to that repository, or traced nowhere and saying it does
|
|
// the same thing (its SKILL.md's description, as an older download of it
|
|
// does). One traced to another repository, or one of the user's own that
|
|
// describes something else, is another skill by that name, and goes in
|
|
// beside it (skill_beside.go, TestInstallSetPutsAnotherByTheSameNameBeside).
|
|
func followsHere(s *Skill, src Source, from string) bool {
|
|
if src.Kind != "github" || s.Source.remote() || s.Called != "" {
|
|
return false
|
|
}
|
|
// where it is traced to: CC Switch's record, the skills CLI's lock,
|
|
// the git checkout its folder is in, or the repository it was grouped
|
|
// with (skill_from.go)
|
|
if r := (&tracer{}).repoOf(s); r != "" {
|
|
return strings.EqualFold(r, src.Repo)
|
|
}
|
|
here, ok := readMeta(skillDir(s.Name))
|
|
there, ok2 := readMeta(from)
|
|
return ok && ok2 && here.Description != "" && here.Description == there.Description
|
|
}
|
|
|
|
// linkSkill puts the skill fetched at from, at path of src, in the place
|
|
// of the library's skill s, which then updates from src. The agents named
|
|
// get it too. kept is whether s's own files weren't the fetched ones and
|
|
// went to the backups.
|
|
func (l *Library) linkSkill(s *Skill, src Source, path, from string, agents []string) (kept bool, err error) {
|
|
src.Path = path
|
|
dir := skillDir(s.Name)
|
|
if linked(dir) || !sameTree(dir, from) {
|
|
kept = !linked(dir)
|
|
up := &skillUpdate{name: s.Name, src: &src, adopt: true, from: from}
|
|
if err := up.apply(l, Targets()); err != nil {
|
|
return false, err
|
|
}
|
|
} else {
|
|
// its files are the source's already: only where it updates from
|
|
// is new
|
|
s.Hash, s.Own, s.Commit = hashDir(dir), ownHash(dir), ""
|
|
forgetCheck(s.Name)
|
|
}
|
|
s.Source, s.From, s.Gone = &src, "", ""
|
|
for _, a := range agents {
|
|
if !slices.Contains(s.Agents, a) {
|
|
s.Agents = append(s.Agents, a)
|
|
}
|
|
}
|
|
return kept, nil
|
|
}
|