library: Antigravity and Crush get copies of skills on Windows (#6610, #5107)

On Windows without the right to make a symlink, magpie links a skill with
a junction. Go 1.23+ lists a junction as ModeIrregular, neither a folder
nor a symlink, and Antigravity (the app and agy: customizations'
discoverInSubDirsFiltered) and Crush (internal/skills on fastwalk, which
follows only a ModeSymlink) keep only folders and symlinks, so a
junctioned skill never showed in them. dsh, pi and the other Node, Bun,
Rust and Python agents follow a junction.

Checked against the real apps on xiaomi-gpu (Windows 11) in a sandbox
USERPROFILE: Antigravity 2.30.0's language_server.exe (--standalone)
GetAllSkills lists a skill in a folder and one behind a symlink, not one
behind a junction. crush v0.101.0's `crush run` request to a local
capture server listed the folder and the symlink, not the junction. On
macOS agy 1.5.8 (ACP session/new, available_commands_update) takes a
symlink that leads out of ~/.gemini/config, so #6610's "confined to the
folder" filter doesn't touch magpie's links there.

- junctionBlind (agy, antigravity, crush) and skipsJunctions: on Windows
  these targets have Copy, so they get marked copies, made again when
  the library's changes, and the Library page shows "Only ever takes
  copies" for them. A junction an older magpie made becomes a copy.
- inShared: a link in ~/.agents/skills is no skill to them, so Crush,
  which reads that folder too, gets its own copy.
- A project's .agents/skills entry that one of them reads is a copy
  (syncFolder's per-entry flag); one no such agent reads is a link again.
- takeEdits takes an edit made in a project's copy into the library, as
  one in an agent's copy is, so a copy a user edits isn't undone by the
  next sync (Project.Copy's copies too, which were made again over an
  edit before).
- behind lists these agents' stale copies.

Run:
- go vet ./internal/library, GOOS=windows and GOOS=linux go vet, gofmt -l:
  clean (mote).
- go test -count=1 ./internal/library: ok on mote (macOS) 107.9s and on
  xiaomi-gpu (Windows 11) 440.0s, at this change on 0caa09b3d.
- go test -run JunctionBlind ./internal/library: ok on mote and on the
  Windows box (-v: all four new tests PASS, TestJunctionIsALink too).
- After rebasing on be7d22edd: go test ./internal/library on mote, ok.

Broken by hand:
- Without `t.Copy = skipsJunctions(a.ID)`, the inShared check and the
  project per-entry copy: TestJunctionBlindAgentsGetCopies,
  ...AgentSkipsSharedLink and ...ProjectCopies red on mote; on Windows
  TestJunctionBlindJunctionBecomesCopy red (both entries stay junctions,
  Lstat mode 2684354563 attrs, not a dir).
- Without the project loop in takeEdits: TestJunctionBlindProjectCopies
  red, the user's edit replaced by the library's.

Not tried: magpie's own binary syncing a real Antigravity on Windows end
to end (the apps were checked against a folder, a symlink and a junction
made by hand; magpie's copy is a plain folder, which the test checks a Go
ReadDir sees as one). Antigravity and Crush on Linux (symlinks there,
which both take). The full go test ./... suite.
This commit is contained in:
yetone
2026-11-14 15:05:21 +08:00
parent 8e1d3095a2
commit df2b819c67
9 changed files with 294 additions and 32 deletions
File diff suppressed because one or more lines are too long
+5 -3
View File
@@ -13,9 +13,11 @@ import (
// dirLink makes link a link to the folder target. Windows lets a user make
// a symlink only with Developer Mode on or as an administrator (#973);
// without that it is a junction, which every user can make and every
// program follows as it does a symlink to a folder. A junction can't point
// at a network share: that is still the symlink's error.
// without that it is a junction, which every user can make and most
// programs follow as they do a symlink to a folder; a Go program's walk
// may not, so the agents that skip one get copies (skipsJunctions). A
// junction can't point at a network share: that is still the symlink's
// error.
func dirLink(target, link string) error {
err := os.Symlink(target, link)
if err == nil || !errors.Is(err, windows.ERROR_PRIVILEGE_NOT_HELD) {
+43
View File
@@ -46,3 +46,46 @@ func TestJunctionIsALink(t *testing.T) {
t.Errorf("a failed junction left %s: %v", q, err)
}
}
// #6610: Antigravity skips a junction, so its junction from an older
// magpie is made a copy, a real folder (not ModeIrregular to a Go walk),
// in its own folder and in a project's .agents/skills.
func TestJunctionBlindJunctionBecomesCopy(t *testing.T) {
h, cfg := antigravity(t)
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"agy"}))
proj := filepath.Join(t.TempDir(), "app")
write(t, filepath.Join(proj, ".git", "HEAD"), "ref: refs/heads/main\n")
ok(t)(AddProject(proj))
ok(t)(ProjectSkill(proj, "pdf", []string{"agy"}))
ps := []string{filepath.Join(cfg, "skills/pdf"), filepath.Join(proj, ".agents/skills/pdf")}
for _, p := range ps {
if err := os.RemoveAll(p); err != nil {
t.Fatal(err)
}
if err := junction(skillDir("pdf"), p); err != nil {
t.Fatal(err)
}
}
ok(t)(Sync())
for _, p := range ps {
fi, err := os.Lstat(p)
if err != nil || !fi.IsDir() || fi.Mode()&(os.ModeIrregular|os.ModeSymlink) != 0 || !ours(p, "pdf") {
t.Errorf("%s: %v %v", p, fi, err)
continue
}
es, err := os.ReadDir(filepath.Dir(p))
if err != nil {
t.Fatal(err)
}
for _, e := range es {
if e.Name() == "pdf" && !e.IsDir() {
t.Errorf("%s: a walk doesn't see a folder: %v", p, e.Type())
}
}
if _, err := os.Stat(filepath.Join(p, "SKILL.md")); err != nil {
t.Error(err)
}
}
}
+157
View File
@@ -0,0 +1,157 @@
package library
import (
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
"time"
)
// onWindowsLinks makes the sync judge links as it does on Windows, where
// magpie's link may be a junction (skipsJunctions).
func onWindowsLinks(t *testing.T) {
t.Helper()
old := linkOS
linkOS = "windows"
t.Cleanup(func() { linkOS = old })
}
// #6610, #5107: on Windows, Antigravity and Crush skip a junction in their
// skills folder, so they get marked copies, made again when the library's
// changes; an edit made in one goes to the library and to the agents
// given links. Elsewhere they get links.
func TestJunctionBlindAgentsGetCopies(t *testing.T) {
h, cfg := antigravity(t)
write(t, filepath.Join(h, ".config/crush/crush.json"), "{}")
for _, id := range []string{"agy", "crush"} {
if tg := targetByID(id); tg == nil || tg.Copy != (runtime.GOOS == "windows") {
t.Fatalf("%s here: %+v", id, tg)
}
}
onWindowsLinks(t)
for _, id := range []string{"agy", "crush"} {
if tg := targetByID(id); tg == nil || !tg.Copy {
t.Fatalf("%s on Windows: %+v", id, tg)
}
}
if tg := targetByID("claude"); tg == nil || tg.Copy {
t.Fatalf("claude on Windows: %+v", tg)
}
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"agy", "crush", "claude"}))
ag, cr, cl := filepath.Join(cfg, "skills/pdf"), filepath.Join(h, ".config/crush/skills/pdf"), filepath.Join(h, ".claude/skills/pdf")
for _, p := range []string{ag, cr} {
if isLink(t, p) || !ours(p, "pdf") {
t.Fatalf("%s isn't magpie's copy", p)
}
}
if runtime.GOOS != "windows" && !isLink(t, cl) {
t.Fatal("Claude Code's isn't a link")
}
v, err := Read(nil)
if err != nil {
t.Fatal(err)
}
for _, a := range v.Agents {
if (a.ID == "agy" || a.ID == "crush") && (!a.MustCopy || a.How != HowCopy) {
t.Errorf("%s: must copy %v, how %q", a.ID, a.MustCopy, a.How)
}
}
// the user edits Antigravity's copy, then syncs (twice: the next start)
time.Sleep(20 * time.Millisecond)
write(t, filepath.Join(ag, "SKILL.md"), "---\nname: pdf\ndescription: Edited in Antigravity\n---\n")
for range 2 {
ok(t)(Sync())
for _, p := range []string{ag, cr, cl, filepath.Join(src, "pdf")} {
if s := read(t, filepath.Join(p, "SKILL.md")); !strings.Contains(s, "Edited in Antigravity") {
t.Fatalf("%s after a sync:\n%s", p, s)
}
}
if isLink(t, ag) || !ours(ag, "pdf") {
t.Fatal("Antigravity's isn't magpie's copy any more")
}
}
// the library's changes: the copies are behind till a sync
time.Sleep(20 * time.Millisecond)
write(t, filepath.Join(src, "pdf/SKILL.md"), "---\nname: pdf\ndescription: Changed\n---\n")
v, _ = Read(nil)
if b := v.Skills[0].Behind; !slices.Equal(b, []string{"agy", "crush"}) {
t.Fatalf("behind: %v", b)
}
ok(t)(Sync())
for _, p := range []string{ag, cr} {
if s := read(t, filepath.Join(p, "SKILL.md")); !strings.Contains(s, "Changed") {
t.Errorf("%s wasn't copied again:\n%s", p, s)
}
}
}
// Crush reads ~/.agents/skills besides its own folder; magpie's link
// there is no skill to it on Windows, so it gets its own copy.
func TestJunctionBlindAgentSkipsSharedLink(t *testing.T) {
h := sandbox(t)
write(t, filepath.Join(h, ".config/crush/crush.json"), "{}")
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
ok(t)(SetSkillsWhere(SkillsInShared))
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"crush"}))
shared, cr := filepath.Join(sharedSkillsDir(), "pdf"), filepath.Join(h, ".config/crush/skills/pdf")
if !isLink(t, shared) {
t.Fatal("no link in ~/.agents/skills")
}
if runtime.GOOS != "windows" {
if _, err := os.Lstat(cr); !os.IsNotExist(err) {
t.Fatalf("Crush got a second one beside ~/.agents/skills: %v", err)
}
}
onWindowsLinks(t)
ok(t)(Sync())
if isLink(t, cr) || !ours(cr, "pdf") {
t.Fatal("Crush has no copy of its own on Windows")
}
}
// A project's .agents/skills entry that Antigravity reads is a copy on
// Windows, and an edit made in it goes to the library; one no such agent
// reads is a link again.
func TestJunctionBlindProjectCopies(t *testing.T) {
h, proj := projectLib(t)
onWindowsLinks(t)
ok(t)(ProjectSkill(proj, "pdf", []string{"agy", "claude"}))
sh, cl := filepath.Join(proj, ".agents/skills/pdf"), filepath.Join(proj, ".claude/skills/pdf")
if isLink(t, sh) || !ours(sh, "pdf") {
t.Fatal(".agents/skills/pdf isn't magpie's copy")
}
if runtime.GOOS != "windows" && !isLink(t, cl) {
t.Fatal(".claude/skills/pdf isn't a link")
}
// the user edits the project's copy, then syncs
time.Sleep(20 * time.Millisecond)
write(t, filepath.Join(sh, "SKILL.md"), "---\nname: pdf\ndescription: Edited in the project\n---\n")
for range 2 {
ok(t)(Sync())
for _, p := range []string{sh, cl, filepath.Join(h, "src/pdf")} {
if s := read(t, filepath.Join(p, "SKILL.md")); !strings.Contains(s, "Edited in the project") {
t.Fatalf("%s after a sync:\n%s", p, s)
}
}
}
if isLink(t, sh) || !ours(sh, "pdf") {
t.Fatal("the project's copy isn't magpie's any more")
}
// Antigravity unticked: Codex's entry is a link again (on Windows a
// copy as fresh as the library's stands for one)
ok(t)(ProjectSkill(proj, "pdf", []string{"codex"}))
if runtime.GOOS != "windows" && !isLink(t, sh) {
t.Error(".agents/skills/pdf is still a copy")
}
}
+13 -6
View File
@@ -162,13 +162,20 @@ func (l *Library) syncFolder(p *Project, res *Result, hubs map[string]*Server) {
res.Problems = append(res.Problems, Problem{Agent: p.Dir, What: "project:" + name, Error: err.Error()})
}
want := map[string]string{} // entry → the skill
// the entries given as copies: all of them in a project that takes
// copies, else those an agent reads that skips a junction
// (skipsJunctions), which is magpie's link on Windows without the
// right to make a symlink
copies := map[string]bool{}
for name, agents := range p.Skills {
if l.skill(name) == nil {
continue
}
for _, id := range agents {
if d := ProjectSkillsDir(id); d != "" {
want[d+"/"+name] = name
e := d + "/" + name
want[e] = name
copies[e] = copies[e] || p.Copy || skipsJunctions(id)
}
}
}
@@ -195,7 +202,7 @@ func (l *Library) syncFolder(p *Project, res *Result, hubs map[string]*Server) {
})
for _, e := range entries {
name := want[e]
switch err := p.place(e, name); {
switch err := p.place(e, name, copies[e]); {
case err == nil:
placed = append(placed, e)
case errors.Is(err, errForeign):
@@ -241,7 +248,7 @@ var errForeign = errors.New("not magpie's")
// place puts a skill at e in the project: a link to the library's, or a
// copy made again whenever the library's differs from it.
func (p *Project) place(e, name string) error {
func (p *Project) place(e, name string, asCopy bool) error {
abs := filepath.Join(p.Dir, filepath.FromSlash(e))
if fi, err := os.Lstat(abs); err == nil {
if !ours(abs, name) {
@@ -249,7 +256,7 @@ func (p *Project) place(e, name string) error {
}
link := linkEntry(fi)
// a copy stands for a link on Windows without the right to make one
if !p.Copy && link {
if !asCopy && link {
return nil
}
if !link {
@@ -257,7 +264,7 @@ func (p *Project) place(e, name string) error {
if err != nil {
return err
}
if (p.Copy || runtime.GOOS == "windows") && current {
if (asCopy || runtime.GOOS == "windows") && current {
return nil
}
}
@@ -265,7 +272,7 @@ func (p *Project) place(e, name string) error {
if err := p.mkdirs(filepath.Dir(abs)); err != nil {
return err
}
if !p.Copy {
if !asCopy {
if err := unlink(abs); err != nil {
return err
}
+41 -20
View File
@@ -78,27 +78,48 @@ func (l *Library) takeEdits(targets []*Target, res *Result) {
}
edits = append(edits, edit{t.Agent.ID, p, at})
}
// the shared copy too (#4958): an edit made in ~/.agents/skills,
// where no link could be made (Windows without the right to), is
// the library's to take as one in an agent's copy is — before
// syncShared sets the stale copy aside. An agent whose own folder
// that is has had its copy read above.
// a copy outside an agent's own folder: an edit made there is the
// library's to take as one in an agent's copy is
// (a project's that can't be read is said by its sync, as one)
other := func(agent, p string) {
if seen[realDir(p)] || !ours(p, s.Name) || linked(p) {
return
}
seen[realDir(p)] = true
made, ok := copiedAt(p)
if !ok {
return
}
at, err := changedAt(p)
switch {
case err != nil:
if agent != "project" {
failed(agent, s.Name, p, err)
}
case !at.After(made):
if l.untouched == nil {
l.untouched = map[string]bool{}
}
l.untouched[p] = true
case !sameTree(p, lib):
edits = append(edits, edit{agent, p, at})
}
}
// the shared copy (#4958), in ~/.agents/skills where no link could
// be made (Windows without the right to), before syncShared sets
// the stale copy aside. An agent whose own folder that is has had
// its copy read above.
if !seen[realDir(sharedSkillsDir())] {
p := filepath.Join(sharedSkillsDir(), s.Name)
if ours(p, s.Name) && !linked(p) {
made, ok := copiedAt(p)
if ok {
at, err := changedAt(p)
switch {
case err != nil:
failed("agents", s.Name, p, err)
case !at.After(made):
if l.untouched == nil {
l.untouched = map[string]bool{}
}
l.untouched[p] = true
case !sameTree(p, lib):
edits = append(edits, edit{"agents", p, at})
other("agents", filepath.Join(sharedSkillsDir(), s.Name))
}
// a project's copies: of a project that takes copies, and those
// of an agent that skips a junction (#6610), where a link was
// edited in place in the library's own folder
for _, p := range l.Projects {
for _, f := range append([]*Project{p}, p.Trees...) {
for _, e := range f.Placed {
if filepath.Base(filepath.FromSlash(e)) == s.Name {
other("project", filepath.Join(f.Dir, filepath.FromSlash(e)))
}
}
}
+1 -1
View File
@@ -121,7 +121,7 @@ func relink(agent, p, name string) (bool, error) {
func (l *Library) behind(targets []*Target) map[string][]string {
out := map[string][]string{}
for _, t := range targets {
if t.Skills == "" || t.Desktop != nil || t.Agent.WSL != "" || l.howOf(t.Agent.ID) != HowCopy {
if t.Skills == "" || t.Desktop != nil || t.Agent.WSL != "" || l.howOf(t.Agent.ID) != HowCopy && !skipsJunctions(t.Agent.ID) {
continue
}
for _, s := range l.Skills {
+5
View File
@@ -722,6 +722,11 @@ func (l *Library) syncSkills(t *Target, res *Result, all []*Target) {
if s == nil || !t.readsSharedDir() || realDir(t.Skills) == shared {
return false
}
// a link there is no skill to an agent that skips a junction
// (skipsJunctions): it gets its own copy
if skipsJunctions(id) && linked(filepath.Join(sharedSkillsDir(), s.Name)) {
return false
}
// the library's skill is kept in the shared folder itself (brought
// in from there): every agent reading it has it, ticked or not (#595)
if sharedHas(s.Name) || l.inSharedHere(s) {
+28 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"slices"
"strings"
@@ -43,7 +44,8 @@ type Target struct {
Note string
// Copy is an agent that gets a copy of each skill, made again when
// the library's changes, rather than a link: one in a WSL distro whose
// skills folder is on a Windows drive (wslStored).
// skills folder is on a Windows drive (wslStored), LiveAgent, and on
// Windows one that skips a junction (skipsJunctions).
Copy bool
// Store, for an agent in a WSL distro, is magpie's folder there
// (wslStoreRel) holding one copy of each skill given to the distro's
@@ -205,6 +207,7 @@ func targetOf(a *agent.Agent) *Target {
t.Instructions = filepath.Join(d, "GEMINI.md")
t.MCP = &mcpFile{Path: filepath.Join(d, "mcp_config.json"), Format: fmtAntigravity}
t.Skills = filepath.Join(d, "skills")
t.Copy = skipsJunctions(a.ID)
case "opencode", "deveco":
// DevEco Code is OpenCode's fork and reads as it does: AGENTS.md
// in its config folder, else Claude Code's CLAUDE.md, skills there
@@ -313,6 +316,7 @@ func targetOf(a *agent.Agent) *Target {
t.MCP = &mcpFile{Path: a.Path, Format: fmtCrush}
t.Skills = filepath.Join(filepath.Dir(a.Path), "skills")
t.SkillsAlso = []string{"claude"}
t.Copy = skipsJunctions(a.ID)
case "zcode":
// ZCode's own servers are its cli/config.json's mcp.servers (the
// app's MCP settings write there); AGENTS.md and skills beside it
@@ -1057,6 +1061,29 @@ func (l *Library) held(have []*Target) []*Target {
return out
}
// junctionBlind are the agents that, on Windows, skip a junction in a
// skills folder while they take a folder or a symlink there: Go programs
// whose walk keeps an entry only when it IsDir or is a ModeSymlink, and Go
// from 1.23 lists a junction as neither but ModeIrregular. Antigravity,
// the app and agy alike (customizations' discoverInSubDirsFiltered, #5107,
// #6610), and Crush (internal/skills on fastwalk with Follow, which follows
// only a ModeSymlink). magpie's link on Windows is a junction when the
// user may not make a symlink (dirLink, #973), so these get copies there:
// GetAllSkills of Antigravity 2.30's language server and Crush 0.101's
// prompt list a skill in a folder or behind a symlink, and not one behind
// a junction.
var junctionBlind = []string{"agy", "antigravity", "crush"}
// linkOS is the system magpie's links are made on, runtime.GOOS but in a
// test.
var linkOS = runtime.GOOS
// skipsJunctions is whether the agent skips magpie's links in its skills
// folders on this system (junctionBlind).
func skipsJunctions(id string) bool {
return linkOS == "windows" && slices.Contains(junctionBlind, id)
}
// readsShared are the agents that read ~/.agents/skills as well as their
// own folder (each one's docs or source): Kimi Code's own is
// ~/.kimi-code/skills besides it (#4379). OmO's engine, senpi, a fork of