library: agy's GEMINI.md is no longer emptied by Antigravity's app switched off
vizmoe42 on X (v0.1.4271): Library -> Instructions had agy CLI's
GEMINI.md switched on, but ~/.gemini/config/GEMINI.md held nothing.
agy and Antigravity's app share that file (and its folder). With the
built-in agy the targets run agy first, then Antigravity; agy wrote its
part and the unticked Antigravity row, wanting nothing, took it out
again, leaving the file empty or gone. The unticked row also showed
"edited". With agy on its plugin the order is reversed, so it worked by
luck there.
syncInstructions now takes every target. A file another target reads
too belongs to the one switched on (instrOwner): the others leave it
and drop their own record. The Edited check compares against that
owner's text (wantedIn). The path itself is right: agy 1.5.9 reads
~/.gemini/GEMINI.md, ~/.gemini/AGENTS.md and their config/ copies
(binary strings and `agy changelog`, sandbox HOME). MCP and skills in
the shared folder already behaved; probed, unchanged.
Existing users: agy's record says written but the file has no block,
so the next start-up Sync writes it, without switching anything again
(covered by the test).
Run:
- TestAntigravitySharedInstructionsFile (agy and antigravity subtests),
red on the old code (file empty after the switch; agy row Edited),
green with the fix, on mica.
- go vet ./internal/library; go test -count=1 ./internal/library
./internal/gui ./internal/tui ./internal/cli: all ok on mica.
- At the pushed head (rebased on e47abdf46, no library change upstream):
GOOS=linux and GOOS=windows go vet ./internal/library and the
library's Antigravity and Instruction tests, ok on mote.
- gofmt -l clean.
Not tried: a real agy session reading the written file; Windows or
WSL; the GUI clicked by hand (no GUI file changed).
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -154,3 +154,57 @@ func TestAntigravityAppTarget(t *testing.T) {
|
||||
t.Errorf("project skills: %q", ProjectSkillsDir("antigravity"))
|
||||
}
|
||||
}
|
||||
|
||||
// vizmoe42 on X: agy switched on in Instructions, and no GEMINI.md in
|
||||
// ~/.gemini/config. The Antigravity app, here too and switched off, reads
|
||||
// the same file, and its write took agy's part out again at once. One
|
||||
// switched on keeps the file it shares with one switched off, whichever
|
||||
// comes first; the one off doesn't call the part "edited"; and a file the
|
||||
// old write left empty is written again by the next sync, the switch left
|
||||
// as it was.
|
||||
func TestAntigravitySharedInstructionsFile(t *testing.T) {
|
||||
for _, on := range []string{"agy", "antigravity"} {
|
||||
t.Run(on, func(t *testing.T) {
|
||||
h, cfg := antigravity(t)
|
||||
write(t, filepath.Join(h, ".gemini/antigravity/agyhub_summaries_proto.pb"), "x")
|
||||
p := filepath.Join(cfg, "GEMINI.md")
|
||||
for _, id := range []string{"agy", "antigravity"} {
|
||||
if tg := targetByID(id); tg == nil || tg.Instructions != p {
|
||||
t.Fatalf("%s: %+v", id, tg)
|
||||
}
|
||||
}
|
||||
want := blockBegin + "\nUse tabs.\n" + blockEnd + "\n"
|
||||
shared := "Use tabs."
|
||||
ok(t)(SaveInstructions(InstructionsChange{Shared: &shared, Agents: []string{on}}))
|
||||
if s := read(t, p); s != want {
|
||||
t.Fatalf("after the switch:\n%q", s)
|
||||
}
|
||||
ok(t)(Sync())
|
||||
if s := read(t, p); s != want {
|
||||
t.Fatalf("after a sync:\n%q", s)
|
||||
}
|
||||
v, err := ReadInstructions()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, a := range v.Agents {
|
||||
if (a.Agent == "agy" || a.Agent == "antigravity") && (a.Edited || a.On != (a.Agent == on)) {
|
||||
t.Errorf("row %+v", a)
|
||||
}
|
||||
}
|
||||
|
||||
// as the old write left it: the part taken out, the file empty
|
||||
write(t, p, "")
|
||||
ok(t)(Sync())
|
||||
if s := read(t, p); s != want {
|
||||
t.Fatalf("a sync didn't write the emptied file again:\n%q", s)
|
||||
}
|
||||
|
||||
// both off: the part goes
|
||||
ok(t)(SaveInstructions(InstructionsChange{Agents: []string{}}))
|
||||
if s := read(t, p); s != "" {
|
||||
t.Errorf("both off:\n%q", s)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,8 +208,9 @@ func PublishMemory(due bool) (*Result, error) {
|
||||
if b == nil {
|
||||
b = newBackups()
|
||||
}
|
||||
for _, t := range Targets() {
|
||||
l.syncInstructions(t, b, res, true)
|
||||
all := Targets()
|
||||
for _, t := range all {
|
||||
l.syncInstructions(t, all, b, res, true)
|
||||
}
|
||||
res.Backup = b.dir
|
||||
if b.dir != "" {
|
||||
@@ -332,8 +333,10 @@ func (l *Library) instructionsLost() bool {
|
||||
// them, and the parts out there are then the only copy left (#5709, where
|
||||
// a start-up apply with an empty Library wiped nine agents' files). It is
|
||||
// a write of the page — a take-back, made with the library as the user
|
||||
// left it — that takes a part out.
|
||||
func (l *Library) syncInstructions(t *Target, b *backups, res *Result, auto bool) {
|
||||
// left it — that takes a part out. A file other agents in all read too is
|
||||
// written for the one of them switched on (instrOwner), never emptied by
|
||||
// another switched off.
|
||||
func (l *Library) syncInstructions(t *Target, all []*Target, b *backups, res *Result, auto bool) {
|
||||
if res.unreached(t) {
|
||||
return
|
||||
}
|
||||
@@ -342,6 +345,14 @@ func (l *Library) syncInstructions(t *Target, b *backups, res *Result, auto bool
|
||||
}
|
||||
id := t.Agent.ID
|
||||
a := l.applied(id)
|
||||
if o := l.instrOwner(t, all); o != "" && o != id {
|
||||
// the file is the part of another agent that reads it, switched
|
||||
// on: Antigravity's app, switched off, took agy's part out of
|
||||
// ~/.gemini/config/GEMINI.md they both read, as soon as agy's
|
||||
// was written (vizmoe42 on X)
|
||||
a.Instructions, a.InstrHash = false, ""
|
||||
return
|
||||
}
|
||||
if slices.Contains(l.Instructions.Agents, id) {
|
||||
// a text that can't be read is unknown, not empty: writing what
|
||||
// is left would take the agent's part out or cut it down (#5709)
|
||||
@@ -443,6 +454,30 @@ func (l *Library) syncInstructions(t *Target, b *backups, res *Result, auto bool
|
||||
res.changed(id)
|
||||
}
|
||||
|
||||
// instrOwner is the agent whose part the file t's instructions are in
|
||||
// holds when it is also the file of other agents in all: the first of
|
||||
// them switched on, "" when none is. Antigravity's app and agy both read
|
||||
// ~/.gemini/config/GEMINI.md; one switched off takes nothing out of the
|
||||
// file the other is switched on for.
|
||||
func (l *Library) instrOwner(t *Target, all []*Target) string {
|
||||
p := filepath.Clean(t.Instructions)
|
||||
for _, o := range all {
|
||||
if o.Instructions != "" && o.Field == t.Field && filepath.Clean(o.Instructions) == p && slices.Contains(l.Instructions.Agents, o.Agent.ID) {
|
||||
return o.Agent.ID
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// wantedIn is what the file t's instructions are in is to hold: the part
|
||||
// of the agent switched on for it (instrOwner), else t's agent's own.
|
||||
func (l *Library) wantedIn(t *Target, all []*Target) string {
|
||||
if o := l.instrOwner(t, all); o != "" {
|
||||
return l.wanted(o)
|
||||
}
|
||||
return l.wanted(t.Agent.ID)
|
||||
}
|
||||
|
||||
// AgentInstructions is one agent's instructions file as the page shows it.
|
||||
type AgentInstructions struct {
|
||||
Agent string `json:"agent"`
|
||||
@@ -510,7 +545,7 @@ func (l *Library) instructionsView(targets []*Target, asleep []*agent.Agent) *In
|
||||
if o := own(file); o != "" {
|
||||
ai.Own = strings.Count(o, "\n") + 1
|
||||
}
|
||||
if _, have, _, ok := split(file); ok && have != l.wanted(id) && !l.isSetFile(t.Instructions) {
|
||||
if _, have, _, ok := split(file); ok && have != l.wantedIn(t, targets) && !l.isSetFile(t.Instructions) {
|
||||
ai.Edited = true
|
||||
}
|
||||
if t.Override != "" && readText(t.Override) != "" {
|
||||
@@ -570,8 +605,9 @@ func changeInstructions(f func(l *Library) error) (*Result, error) {
|
||||
if b == nil {
|
||||
b = newBackups()
|
||||
}
|
||||
for _, t := range Targets() {
|
||||
l.syncInstructions(t, b, res, false)
|
||||
all := Targets()
|
||||
for _, t := range all {
|
||||
l.syncInstructions(t, all, b, res, false)
|
||||
}
|
||||
res.Backup = b.dir
|
||||
if b.dir != "" {
|
||||
|
||||
@@ -114,7 +114,7 @@ func syncSteps(all, gone []*Target, b *backups, res *Result) []func(*Library) {
|
||||
steps := []func(*Library){func(l *Library) { l.followMovedSkills() }}
|
||||
for _, t := range all {
|
||||
steps = append(steps, func(l *Library) {
|
||||
l.syncInstructions(t, b, res, true)
|
||||
l.syncInstructions(t, all, b, res, true)
|
||||
l.syncMCP(t, b, res)
|
||||
l.syncHooks(t, b, res)
|
||||
l.syncEnv(t, b, res)
|
||||
|
||||
Reference in New Issue
Block a user