diff --git a/docs/reference.md b/docs/reference.md index c45c5530c..3ed4975cc 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -3032,6 +3032,13 @@ ever stores ciphertext. Each machine writes only over the version it read (a conditional write), so an update that another machine made in between is merged rather than lost. +A change to an agent's model (or any of its fields) on one machine reaches +the others. When sync changes one on a machine and you set it back there, +that machine keeps its own: the other machines' picks no longer change it +there, and its picks stay there, while everything else keeps syncing. +Settings → Sync lists those fields under **Kept on this computer**, and +**Follow the others** takes the synced value again. + ```sh magpie webdav on https://dav.jianguoyun.com/dav/ user=me@example.com magpie s3 on s3://my-bucket/magpie endpoint=https://.r2.cloudflarestorage.com access-key-id=… diff --git a/docs/subsystems/sync-backup.md b/docs/subsystems/sync-backup.md index a882710ed..25f46a9c2 100644 --- a/docs/subsystems/sync-backup.md +++ b/docs/subsystems/sync-backup.md @@ -61,6 +61,24 @@ this computer's values for a provider it has, and brings a new one without `KeepLoginAs`, an account signed in on the other computer; `hashes` blanks all three (`TestMirrorKeepsKeepLogin`, `TestKeepLoginIsNoChange`). +The agents part keeps a computer's own pick the same way, field by field +(hayden4608 on Discord: two computers on one GitHub sync, each wanting its own +Codex model, set each other's on every sync). Each field a sync changes here +is recorded in sync-state.json (`Brought`), with the value it wrote over when +that value was picked here, not brought by an earlier sync (`Replaced`). A +field the user then sets back to that value is this computer's own (`Own`, +[`noticeOwn`](../../internal/davsync/own.go)). Setting a new value is a pick +like any other: it goes up, so a change made on either computer still reaches +the other. For an own field, `hashesOwn` leaves it out, so picking it is no +change to push and the server's value is no change to bring; `bringAgents` +brings the agents' other fields and puts an own field back if a provider moved +it; `keepServersOwn` keeps the server's value of it in what this computer +pushes. Settings → Sync lists the own fields under Kept on this computer, with +**Follow the others** (`davsync.Follow`): the next sync brings the server's +values in and clears `Own`. A Restore brings everything and clears it too. The +three maps survive a change of server (`TestOwnModelStaysOnEachComputer`, +`TestNewPicksStillGoBothWays`, `sync-own-fields.test.cjs`). + Sharing turned on at one computer never turns it on or off at another (Lullaby on Discord). A backup restored onto a new computer leaves sharing as that computer has it, off on a fresh one: sharing opens the gateway to the diff --git a/internal/davsync/davsync.go b/internal/davsync/davsync.go index b2f480600..f5c464f3d 100644 --- a/internal/davsync/davsync.go +++ b/internal/davsync/davsync.go @@ -212,6 +212,17 @@ type state struct { // Blind is the last write, when the server didn't check the version // it went over (version.Blind), until a sync reads it back Blind *blind `json:"blind,omitempty"` + // Brought is each agent field's value as the last sync that changed it + // here wrote it, Replaced the value picked here that it wrote over, + // and Own the fields put back to that value since: this computer's + // own, never brought in or taken up (own.go). Follow is Settings + // asking for the own ones to follow the others again, on the next + // sync. They are this computer's choices, kept when sync moves to + // another server. + Brought map[string]string `json:"brought,omitempty"` + Replaced map[string]string `json:"replaced,omitempty"` + Own map[string]bool `json:"own,omitempty"` + Follow bool `json:"follow,omitempty"` } // blind is a write the server didn't check: the file it wrote (Sum), and @@ -475,6 +486,9 @@ type View struct { // account here: sync carries no sign-in, so each is to be signed in to // on this computer before it is listed SignIn []string `json:"signIn,omitempty"` + // Own is the agent fields picked on this computer after a sync set + // them, which sync leaves as they are here (own.go) + Own []OwnField `json:"own,omitempty"` } // OtherView is the other kind's server as the Settings page shows it. @@ -516,6 +530,9 @@ func Status() View { } } v.Usage = c.Usage + if c.Agents { + v.Own = ownFields(st) + } if o := c.Other; o != nil { v.Other = &OtherView{Kind: strings.ToLower(o.config().Kind()), URL: o.URL, User: o.User, PasswordSet: o.Password != "", Endpoint: o.Endpoint, Region: o.Region, PathStyle: o.PathStyle, Branch: o.Branch} @@ -664,7 +681,7 @@ func syncNow(ctx context.Context, force bool) error { } st := loadState() if st.Key != stateKey(c) { // another folder or passphrase: start afresh - st = state{Key: stateKey(c)} + st = state{Key: stateKey(c), Brought: st.Brought, Replaced: st.Replaced, Own: st.Own, Follow: st.Follow} } err = syncOnce(ctx, c, &st) if errors.Is(err, errChanged) { // another computer got in between: again, over its version @@ -1073,9 +1090,25 @@ func syncOnce(ctx context.Context, c Config, st *state) error { if err != nil { return err } - L := hashes(local) + // An agent field picked here after a sync set it is this computer's + // own from now on (own.go). prev is the own fields the last sync's + // hashes left out, so this one's compare with them alike: a field + // owned now is a change here, never a change on both sides. own is + // every field kept here this time, and after what the next sync's + // hashes leave out: none of them, once Settings gave them back. + prev := maps.Clone(st.Own) + if c.Agents { + noticeOwn(st, local.Agents) + } + own, after := st.Own, st.Own + follow := st.Follow && len(own) > 0 && c.Agents + if follow { + after = nil + } + st.Follow = false + L := hashesOwn(local, prev) if unchanged { - if maps.Equal(L, st.Local) { + if maps.Equal(L, st.Local) && !follow { return nil // nothing changed on either side } // changed here: merged with the server's file as last seen, or, @@ -1100,7 +1133,7 @@ func syncOnce(ctx context.Context, c Config, st *state) error { if err != nil { return err } - st.Sum, st.Server, st.Remote = sum(sealed), v, hashes(b) + st.Sum, st.Server, st.Remote = sum(sealed), v, hashesOwn(b, after) if v.Blind { were.Sum = st.Sum st.Blind = &were @@ -1112,10 +1145,11 @@ func syncOnce(ctx context.Context, c Config, st *state) error { if err := push(local, "", blind{}); err != nil { return err } - st.Local = L + st.Own = after + st.Local = hashesOwn(local, after) return nil } - if sum(data) == st.Sum && maps.Equal(L, st.Local) { + if sum(data) == st.Sum && maps.Equal(L, st.Local) && !follow { st.Server = ver remember(data) return nil // nothing changed on either side @@ -1177,7 +1211,10 @@ func syncOnce(ctx context.Context, c Config, st *state) error { data = good rebuilt = true // push the merged result even if it matches the cached copy } - R := hashes(remote) + // R compares with the last sync as its hashes were; Rafter is the + // server's file as this sync leaves it read, both before the merge + // below changes remote (a join's unseen gateway keys) + R, Rafter := hashesOwn(remote, prev), hashesOwn(remote, after) first := st.Local == nil merged := remote var bringIn, here, there []string @@ -1194,6 +1231,9 @@ func syncOnce(ctx context.Context, c Config, st *state) error { switch { case lc && !rc: take(&merged, local, p) + if p == "agents" { + keepServersOwn(&merged, remote, own) + } case rc && !lc: if first && p == "settings" { keepUnseenGatewayKeys(&remote, local) @@ -1205,6 +1245,9 @@ func syncOnce(ctx context.Context, c Config, st *state) error { case lc && rc: // both: the newer stays if changed(p, c.Keys).After(remote.Created) { take(&merged, local, p) + if p == "agents" { + keepServersOwn(&merged, remote, own) + } there = append(there, p) } else { bringIn = append(bringIn, p) @@ -1228,20 +1271,43 @@ func syncOnce(ctx context.Context, c Config, st *state) error { saved = dir } for _, p := range bringIn { + if p == "agents" { + got, err := bringAgents(remote.Agents, after) + broughtIn(st, got) + if err != nil { + return fmt.Errorf("bringing in the %s: %w", p, err) + } + continue + } if err := bring(remote, p); err != nil { return fmt.Errorf("bringing in the %s: %w", p, err) } } + if follow && c.Agents && !slices.Contains(bringIn, "agents") { + // the fields given back to sync take the server's values, the + // agents' other fields left as they are here + fields := map[string]string{} + for k := range own { + if v, ok := remote.Agents[k]; ok { + fields[k] = v + } + } + got, err := bringAgents(fields, nil) + broughtIn(st, got) + if err != nil { + return fmt.Errorf("bringing in the agents: %w", err) + } + } + st.Own, R = after, Rafter // the server's file is in; what is pushed next counts as changed here // until the push is done - now := L - if len(bringIn) > 0 { + if len(bringIn) > 0 || follow { if local, err = collect(c); err != nil { return err } - now = hashes(local) } - M, pending := hashes(merged), map[string]string{} + now := hashesOwn(local, after) + M, pending := hashesOwn(merged, after), map[string]string{} for _, p := range Parts { pending[p] = now[p] if M[p] != R[p] && st.Local != nil { diff --git a/internal/davsync/own.go b/internal/davsync/own.go new file mode 100644 index 000000000..9b4026a7d --- /dev/null +++ b/internal/davsync/own.go @@ -0,0 +1,208 @@ +package davsync + +import ( + "context" + "maps" + "slices" + + "github.com/yetone/magpie/internal/agent" + "github.com/yetone/magpie/internal/backup" + "github.com/yetone/magpie/internal/profile" +) + +// An agent's field that sync wrote over a value picked on this computer, +// and that the user then puts back, is this computer's own (hayden4608 on +// Discord: two computers on one GitHub sync, each wanting its own Codex +// model, set each other's every sync). Putting the value back is what says +// it: a new value picked after a sync still goes up, as before, so a +// change made on any computer still reaches the others. From then on sync +// neither brings an own field in nor takes this computer's value up, while +// the agent's other fields, and every other part, still sync. +// +// The state is this computer's alone (sync-state.json): Brought is each +// field's value as the last sync that changed it here wrote it, Replaced +// the value picked here that it wrote over, if it was one (not one an +// earlier sync brought), and Own the fields put back since. Follow, from +// the Settings page, gives the own fields back to sync: the next sync +// brings the server's values in. + +// noticeOwn makes own each field sync wrote over a pick, put back to that +// pick here since. Another value picked since is a pick like any other: it +// goes up, and what sync brought before is forgotten. +func noticeOwn(st *state, here map[string]string) { + for k, v := range st.Brought { + now, ok := here[k] + if !ok || now == v { // the agent isn't here now, or the field is as sync left it + continue + } + if was, ok := st.Replaced[k]; ok && now == was { + if st.Own == nil { + st.Own = map[string]bool{} + } + st.Own[k] = true + } + delete(st.Brought, k) + delete(st.Replaced, k) + } +} + +// withoutOwn is b without this computer's own agent fields: what is +// hashed to tell a change, so a pick of an own field is no change to push +// and the server's value of one is no change to bring. +func withoutOwn(b backup.Bundle, own map[string]bool) backup.Bundle { + if len(own) == 0 || b.Agents == nil { + return b + } + b.Agents = maps.Clone(b.Agents) + for k := range own { + delete(b.Agents, k) + } + return b +} + +// hashesOwn is hashes of b with this computer's own fields left out. +func hashesOwn(b backup.Bundle, own map[string]bool) map[string]string { + return hashes(withoutOwn(b, own)) +} + +// keepServersOwn puts the server's values of this computer's own fields +// back into the agents a sync takes up from here: they never go up. +func keepServersOwn(merged *backup.Bundle, remote backup.Bundle, own map[string]bool) { + if len(own) == 0 { + return + } + a := maps.Clone(merged.Agents) + if a == nil { + a = map[string]string{} + } + for k := range own { + if v, ok := remote.Agents[k]; ok { + a[k] = v + } else { + delete(a, k) + } + } + merged.Agents = a +} + +// brought is a field a bring changed here: the value it wrote over, and +// the value it reads now. +type brought struct{ was, now string } + +// bringAgents puts fields (the server's agents) in here, but for keep's, +// this computer's own. An own field that another's change moved with it +// (a provider re-settling the model behind it) is put back. It returns +// each field the bring changed here. +func bringAgents(fields map[string]string, keep map[string]bool) (map[string]brought, error) { + in := maps.Clone(fields) + for k := range keep { + delete(in, k) + } + before := profile.Fields() + _, err := backup.Restore(backup.Bundle{Agents: in}, backup.Parts{Agents: true}) + after := profile.Fields() + back := map[string]string{} + for k := range keep { + if v, ok := before[k]; ok && after[k] != v { + back[k] = v + } + } + if len(back) > 0 { + if _, berr := profile.ApplyFields(back); berr != nil && err == nil { + err = berr + } + after = profile.Fields() + } + got := map[string]brought{} + for k, v := range after { + if !keep[k] && before[k] != v { + got[k] = brought{before[k], v} + } + } + return got, err +} + +// broughtIn records what a bring set here, and what it wrote over when +// that was picked here rather than brought by an earlier sync. +func broughtIn(st *state, got map[string]brought) { + if len(got) == 0 { + return + } + if st.Brought == nil { + st.Brought = map[string]string{} + } + if st.Replaced == nil { + st.Replaced = map[string]string{} + } + for k, b := range got { + if last, ok := st.Brought[k]; ok && last == b.was { + delete(st.Replaced, k) // sync's own value, written over by sync + } else { + st.Replaced[k] = b.was + } + st.Brought[k] = b.now + } +} + +// OwnField is an agent field kept on this computer, as Settings names it. +type OwnField struct { + Agent string `json:"agent"` // the agent's name + Field string `json:"field"` // the field's label: model, effort… +} + +// ownFields names st's own fields, by agent then field. +func ownFields(st state) []OwnField { + if len(st.Own) == 0 { + return nil + } + agents := map[string]*agent.Agent{} + for _, a := range agent.Detected() { + agents[a.ID] = a + } + keys := slices.Sorted(maps.Keys(st.Own)) + out := make([]OwnField, 0, len(keys)) + for _, k := range keys { + id, field := splitField(k) + f := OwnField{Agent: id, Field: field} + if a := agents[id]; a != nil { + f.Agent = a.Name + if x := a.Field(field); x != nil && x.Label != "" { + f.Field = x.Label + } + } + out = append(out, f) + } + return out +} + +// splitField is a field's agent and key: the last dot, as a WSL distro's +// name may have one (codex@wsl:Ubuntu-24.04.model). +func splitField(k string) (string, string) { + for i := len(k) - 1; i >= 0; i-- { + if k[i] == '.' { + return k[:i], k[i+1:] + } + } + return k, "" +} + +// Follow gives this computer's own agent fields back to sync, and syncs: +// the server's values come in, and the others' picks follow again. +func Follow(ctx context.Context) error { + err := locked(func() error { + if _, ok := Load(); !ok { + return ErrOff + } + st := loadState() + if len(st.Own) == 0 { + return nil + } + st.Follow = true + saveState(st) + return nil + }) + if err != nil { + return err + } + return SyncNow(ctx) +} diff --git a/internal/davsync/own_model_test.go b/internal/davsync/own_model_test.go new file mode 100644 index 000000000..a40e16f31 --- /dev/null +++ b/internal/davsync/own_model_test.go @@ -0,0 +1,251 @@ +package davsync + +import ( + "context" + "os" + "path/filepath" + "slices" + "strings" + "testing" + + "github.com/yetone/magpie/internal/backup" + "github.com/yetone/magpie/internal/profile" + "github.com/yetone/magpie/internal/provider" +) + +// codexPick writes Codex's model and effort into this computer's +// config.toml, as a pick in Codex or in magpie does. +func codexPick(t *testing.T, model, effort string) { + t.Helper() + dir := os.Getenv("CODEX_HOME") + if err := os.MkdirAll(dir, 0o755); err != nil { + t.Fatal(err) + } + body := "model = \"" + model + "\"\nmodel_reasoning_effort = \"" + effort + "\"\n" + if err := os.WriteFile(filepath.Join(dir, "config.toml"), []byte(body), 0o644); err != nil { + t.Fatal(err) + } +} + +func codexHere() (string, string) { + f := profile.Fields() + return f["codex.model"], f["codex.effort"] +} + +// Two computers on one GitHub sync, each wanting its own Codex model +// (hayden4608 on Discord). A sets its model and syncs; B picks another and +// syncs, which brings B's over A's at A's next sync, as before. A puts its +// own back: from then on it stays A's, neither B's later picks come in nor +// A's own go up. The rest still syncs both ways: Codex's effort, Claude +// Code's model, a provider. Follow the others gives it back to sync. +func TestOwnModelStaysOnEachComputer(t *testing.T) { + f := newGithubFixture(t) + ctx := context.Background() + c := githubConfig() + now := func(t *testing.T) { + t.Helper() + if err := Now(ctx); err != nil { + t.Fatal(err) + } + if st := Status(); st.Notice != nil || st.Error != "" { + t.Fatalf("a sync that replaced nothing: %+v %q", st.Notice, st.Error) + } + } + server := func(t *testing.T) map[string]string { + t.Helper() + b, err := backup.Open(f.objects[backupAt], c.Passphrase) + if err != nil { + t.Fatal(err) + } + return b.Agents + } + own := func(t *testing.T, want int) { + t.Helper() + v := Status() + if len(v.Own) != want { + t.Fatalf("own fields: %+v, want %d", v.Own, want) + } + if want == 1 && (!strings.Contains(v.Own[0].Agent, "Codex") || v.Own[0].Field != "model") { + t.Fatalf("own fields: %+v, want Codex's model", v.Own) + } + } + a, b := newComputer(t), newComputer(t) + + // A sets its model and syncs + a.use(t) + codexPick(t, "gpt-a1", "low") + if m, _ := codexHere(); m != "gpt-a1" { + t.Skipf("Codex isn't seen here: %v", profile.Fields()) + } + if err := Configure(c); err != nil { + t.Fatal(err) + } + now(t) + + // B joins: A's model comes in, as before (a joining computer's own + // setup is saved aside, with a notice) + b.use(t) + codexPick(t, "gpt-b0", "low") + if err := Configure(c); err != nil { + t.Fatal(err) + } + if err := Now(ctx); err != nil { + t.Fatal(err) + } + if err := Dismiss(); err != nil { + t.Fatal(err) + } + if m, _ := codexHere(); m != "gpt-a1" { + t.Fatalf("B joining: model %q, want A's", m) + } + + // B picks a new model: it goes up, and comes in at A, as before + codexPick(t, "gpt-b1", "low") + now(t) + if m := server(t)["codex.model"]; m != "gpt-b1" { + t.Fatalf("B's pick didn't go up: %q", m) + } + own(t, 0) + a.use(t) + now(t) + if m, _ := codexHere(); m != "gpt-b1" { + t.Fatalf("A after B's pick: %q", m) + } + + // A puts its own back: it stays on A, the server keeps B's + codexPick(t, "gpt-a1", "low") + now(t) + if m, _ := codexHere(); m != "gpt-a1" { + t.Fatalf("A's own: %q", m) + } + if m := server(t)["codex.model"]; m != "gpt-b1" { + t.Fatalf("A's own went up: %q", m) + } + own(t, 1) + + // B picks again, with another effort, and adds a provider + b.use(t) + now(t) + codexPick(t, "gpt-b2", "high") + if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "fixture-provider-key"}); err != nil { + t.Fatal(err) + } + now(t) + if m := server(t)["codex.model"]; m != "gpt-b2" { + t.Fatalf("B's pick didn't go up: %q", m) + } + + // A picks its own again before it syncs: a change of its own is no + // change on both sides, so B's effort and provider come in with no + // notice, and A's model stays + a.use(t) + codexPick(t, "gpt-a1b", "low") + now(t) + m, e := codexHere() + if m != "gpt-a1b" { + t.Fatalf("B's later pick came over A's own: %q", m) + } + if e != "high" { + t.Fatalf("B's effort didn't come in: %q", e) + } + if !slices.Equal(ids(), []string{"deepseek=fixture-provider-key"}) { + t.Fatalf("B's provider didn't come in: %v", ids()) + } + + // A picks again, a new effort too, and Claude Code's model: those go + // up, Codex's model stays A's + codexPick(t, "gpt-a2", "medium") + if _, err := profile.ApplyFields(map[string]string{"claude.model": "claude-from-a"}); err != nil { + t.Fatal(err) + } + if profile.Fields()["claude.model"] != "claude-from-a" { + t.Skipf("Claude Code isn't seen here: %v", profile.Fields()) + } + now(t) + if got := server(t); got["codex.model"] != "gpt-b2" || got["codex.effort"] != "medium" || got["claude.model"] != "claude-from-a" { + t.Fatalf("A's second pick: server has %q %q %q", got["codex.model"], got["codex.effort"], got["claude.model"]) + } + own(t, 1) + b.use(t) + now(t) + if m, e := codexHere(); m != "gpt-b2" || e != "medium" || profile.Fields()["claude.model"] != "claude-from-a" { + t.Fatalf("B after A's second pick: %q %q %q", m, e, profile.Fields()["claude.model"]) + } + own(t, 0) + + // A follows the others again: the server's model comes in + a.use(t) + if err := Follow(ctx); err != nil { + t.Fatal(err) + } + if m, _ := codexHere(); m != "gpt-b2" { + t.Fatalf("A following: %q", m) + } + if v := Status(); len(v.Own) != 0 || v.Notice != nil { + t.Fatalf("A following: own %+v, notice %+v", v.Own, v.Notice) + } + // and B's next pick reaches A again + b.use(t) + codexPick(t, "gpt-b3", "medium") + now(t) + a.use(t) + now(t) + if m, _ := codexHere(); m != "gpt-b3" { + t.Fatalf("A after following: %q", m) + } +} + +// New picks still go both ways: a computer that picks a model it never had +// changes it for the others, however often the two take turns. Only +// putting back the value sync wrote over keeps one. +func TestNewPicksStillGoBothWays(t *testing.T) { + newGithubFixture(t) + ctx := context.Background() + c := githubConfig() + a, b := newComputer(t), newComputer(t) + a.use(t) + codexPick(t, "gpt-1", "low") + if m, _ := codexHere(); m != "gpt-1" { + t.Skipf("Codex isn't seen here: %v", profile.Fields()) + } + if err := Configure(c); err != nil { + t.Fatal(err) + } + joined := map[computer]bool{a: true} + for _, step := range []struct { + c computer + pick string + model string + }{ + {a, "", "gpt-1"}, + {b, "", "gpt-1"}, + {b, "gpt-2", "gpt-2"}, + {a, "", "gpt-2"}, + {a, "gpt-3", "gpt-3"}, + {b, "", "gpt-3"}, + {b, "gpt-4", "gpt-4"}, + {a, "", "gpt-4"}, + {a, "gpt-5", "gpt-5"}, + {b, "", "gpt-5"}, + } { + step.c.use(t) + if !joined[step.c] { + joined[step.c] = true + if err := Configure(c); err != nil { + t.Fatal(err) + } + } + if step.pick != "" { + codexPick(t, step.pick, "low") + } + if err := Now(ctx); err != nil { + t.Fatal(err) + } + if m, _ := codexHere(); m != step.model { + t.Fatalf("model %q, want %q", m, step.model) + } + if v := Status(); len(v.Own) != 0 { + t.Fatalf("own: %+v", v.Own) + } + } +} diff --git a/internal/davsync/restore.go b/internal/davsync/restore.go index 6264e15a9..2787aff10 100644 --- a/internal/davsync/restore.go +++ b/internal/davsync/restore.go @@ -85,7 +85,7 @@ func Restore(ctx context.Context) ([]string, error) { } st := loadState() if st.Key != stateKey(c) { - st = state{Key: stateKey(c)} + st = state{Key: stateKey(c), Brought: st.Brought, Replaced: st.Replaced, Own: st.Own} } if len(brought) > 0 { kept, err := keepHere(c) @@ -93,6 +93,17 @@ func Restore(ctx context.Context) ([]string, error) { return fmt.Errorf("keeping this computer's setup before restoring: %w", err) } for _, p := range brought { + if p == "agents" { + // the server's whole, the fields kept here too: they + // follow the others again, as Follow leaves them + got, err := bringAgents(remote.Agents, nil) + broughtIn(&st, got) + st.Own, st.Follow = nil, false + if err != nil { + return fmt.Errorf("bringing in the %s: %w", p, err) + } + continue + } if err := bring(remote, p); err != nil { return fmt.Errorf("bringing in the %s: %w", p, err) } @@ -105,7 +116,7 @@ func Restore(ctx context.Context) ([]string, error) { } // as a sync that brought them in leaves it: the next one has // nothing to push back - st.Local, st.Remote, st.Sum, st.Server = hashes(local), R, sum(data), ver + st.Local, st.Remote, st.Sum, st.Server = hashesOwn(local, st.Own), hashesOwn(remote, st.Own), sum(data), ver st.Blind = nil // what is here now is what the server has remember(data) st.Last, st.Error = time.Now(), "" @@ -175,10 +186,10 @@ func Upload(ctx context.Context) error { } st := loadState() if st.Key != stateKey(c) { - st = state{Key: stateKey(c)} + st = state{Key: stateKey(c), Brought: st.Brought, Replaced: st.Replaced, Own: st.Own} } // as the first sync to an empty server leaves it - st.Local, st.Remote, st.Sum, st.Server = hashes(local), hashes(b), sum(sealed), v + st.Local, st.Remote, st.Sum, st.Server = hashesOwn(local, st.Own), hashesOwn(b, st.Own), sum(sealed), v st.Blind = nil // it replaced what wasn't a backup: nothing to merge again remember(sealed) st.Last, st.Error, st.File = time.Now(), "", nil diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index e4a60edba..909ff87ba 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -20016,6 +20016,16 @@ async function renderSync(v) { row(t("Upload this computer's setup"), t("It replaces the file on the server. That file is kept in the sync folder first."), btn(t("Upload…"), () => askUpload(v.serverFile))); } + // agent fields set back here after a sync changed them (hayden4608) + if (v.on && v.agents !== false && v.own?.length) { + const fields = v.own.map((f) => t("{agent} {field}", { agent: f.agent, field: t(f.field) })).join(t(", ")); + row(t("Kept on this computer"), t("{fields}: set back here after a sync changed them, so they stay as picked here.", { fields }), + btn(t("Follow the others"), async (e) => { + e.target.classList.add("busy"); + renderSync(await api("davsync/follow", {}).catch((x) => ({ ...v, error: x.message }))); + refreshAfterSync(); + })).classList.add("wraps", "sync-own"); + } if (v.notice) { const n = v.notice, r = el("div", "row pref sync-note"); const lines = []; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index a55e8d1b8..249cd9374 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2695,6 +2695,10 @@ const I18N = { "Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "供应商:新增 {added} 个,替换 {replaced} 个;Profile {profiles} 个;agent 设置改动 {agents} 项", "Needs a key: {names}": "需要填写 Key:{names}", "This backup's settings use {names}, which isn't signed in on this computer. A backup carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "这份备份的设置用到了 {names},但本机尚未登录。备份只带设置,不带登录信息:要在本机使用,请在 供应商 → 添加供应商 中登录;不在本机使用可忽略。", + "{agent} {field}": "{agent} {field}", + "Kept on this computer": "仅本机保留", + "{fields}: set back here after a sync changed them, so they stay as picked here.": "{fields}:同步改动后在本机改了回来,所以保持本机的选择。", + "Follow the others": "跟随其他电脑", "Your synced settings use {names}, which isn't signed in on this computer. Sync carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "同步过来的设置用到了 {names},但本机尚未登录。同步只带设置,不带登录信息:要在本机使用,请在 供应商 → 添加供应商 中登录;不在本机使用可忽略。", "Plugins added: {names}": "已添加插件:{names}", "Couldn't add the plugin {spec}: {error}": "无法添加插件 {spec}:{error}", @@ -6939,6 +6943,10 @@ const I18N = { "Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "供應商:新增 {added} 個,替換 {replaced} 個;Profile {profiles} 個;agent 設定改動 {agents} 項", "Needs a key: {names}": "需要填寫 Key:{names}", "This backup's settings use {names}, which isn't signed in on this computer. A backup carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "這份備份的設定用到了 {names},但本機尚未登入。備份只帶設定,不帶登入資訊:要在本機使用,請在 供應商 → 新增供應商 中登入;不在本機使用可忽略。", + "{agent} {field}": "{agent} {field}", + "Kept on this computer": "僅本機保留", + "{fields}: set back here after a sync changed them, so they stay as picked here.": "{fields}:同步改動後在本機改了回來,所以保持本機的選擇。", + "Follow the others": "跟隨其他電腦", "Your synced settings use {names}, which isn't signed in on this computer. Sync carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "同步過來的設定用到了 {names},但本機尚未登入。同步只帶設定,不帶登入資訊:要在本機使用,請在 供應商 → 新增供應商 中登入;不在本機使用可忽略。", "Plugins added: {names}": "已新增外掛:{names}", "Couldn't add the plugin {spec}: {error}": "無法新增外掛 {spec}:{error}", @@ -11182,6 +11190,10 @@ const I18N = { "Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "プロバイダ:{added} 件追加、{replaced} 件置換。プロファイル {profiles} 件。エージェント設定 {agents} 件を変更", "Needs a key: {names}": "キーが必要です:{names}", "This backup's settings use {names}, which isn't signed in on this computer. A backup carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "このバックアップの設定は {names} を使っていますが、このコンピュータではまだサインインしていません。バックアップに含まれるのは設定だけで、サインイン情報は含まれません。ここで使うなら プロバイダ → プロバイダを追加 でサインインしてください。使わないなら何もしなくて構いません。", + "{agent} {field}": "{agent} の{field}", + "Kept on this computer": "このコンピュータだけで保持", + "{fields}: set back here after a sync changed them, so they stay as picked here.": "{fields}:同期で変わった後にここで元に戻したため、ここでの選択のままです。", + "Follow the others": "ほかのコンピュータに合わせる", "Your synced settings use {names}, which isn't signed in on this computer. Sync carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "同期した設定は {names} を使っていますが、このコンピュータではまだサインインしていません。同期で届くのは設定だけで、サインイン情報は含まれません。ここで使うなら プロバイダ → プロバイダを追加 でサインインしてください。使わないなら何もしなくて構いません。", "Plugins added: {names}": "追加したプラグイン:{names}", "Couldn't add the plugin {spec}: {error}": "プラグイン {spec} を追加できませんでした:{error}", @@ -15436,6 +15448,10 @@ const I18N = { "Providers: {added} added, {replaced} replaced; {profiles} profiles; {agents} agent settings changed": "Anbieter: {added} hinzugefügt, {replaced} ersetzt; {profiles} Profile; {agents} Agenteneinstellungen geändert", "Needs a key: {names}": "Schlüssel erforderlich: {names}", "This backup's settings use {names}, which isn't signed in on this computer. A backup carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "Die Einstellungen dieser Sicherung nutzen {names}, auf diesem Computer aber nicht angemeldet. Eine Sicherung enthält Einstellungen, keine Anmeldungen: Um es hier zu nutzen, melde dich unter Anbieter → Anbieter hinzufügen an; sonst ist nichts zu tun.", + "{agent} {field}": "{agent}: {field}", + "Kept on this computer": "Nur auf diesem Computer", + "{fields}: set back here after a sync changed them, so they stay as picked here.": "{fields}: nach einer Synchronisierung hier zurückgesetzt, daher bleibt die Auswahl dieses Computers.", + "Follow the others": "Den anderen folgen", "Your synced settings use {names}, which isn't signed in on this computer. Sync carries settings, not sign-ins: to use it here, sign in in Providers → Add a provider; if you don't, nothing needs doing.": "Deine synchronisierten Einstellungen nutzen {names}, auf diesem Computer aber nicht angemeldet. Die Synchronisierung überträgt Einstellungen, keine Anmeldungen: Um es hier zu nutzen, melde dich unter Anbieter → Anbieter hinzufügen an; sonst ist nichts zu tun.", "Plugins added: {names}": "Hinzugefügte Erweiterungen: {names}", "Couldn't add the plugin {spec}: {error}": "Die Erweiterung {spec} konnte nicht hinzugefügt werden: {error}", diff --git a/internal/gui/backup.go b/internal/gui/backup.go index 8da4164c1..75eb124c8 100644 --- a/internal/gui/backup.go +++ b/internal/gui/backup.go @@ -127,6 +127,8 @@ func backupRoutes(mux *http.ServeMux, w Windows) { _, err = davsync.Undo() case "upload": // this computer's setup over a server file that isn't a backup, kept first err = davsync.Upload(ctx) + case "follow": // the agent fields kept on this computer follow the others again + err = busy(davsync.Follow(ctx)) case "reveal": err = w.OpenFolder(filepath.Join(settings.Dir(), "sync")) default: diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index c7223c64f..144ff4264 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -15,8 +15,8 @@ import ( // so a page can't quietly grow back into the core; a change that needs more // raises them and says why in its commit. const ( - appScriptBudget = 1_316_874 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29); back to 1,311,735 with Settings › Models › Web search's rows (renderSearch, renderSearcher, the search APIs' keys) moved out to the search plugin (plugins/search/settings.js), app.js 1,292,527 after it, not lowered further since what is left plus 1.5% is over it (#4133, 10-29); 1,315,316 with the Agents row of a Claude Code or Codex not connected saying the account it is signed in to and switching it to another (Switch accounts only, the owner on X), in place of the failover line's ChatGPT accounts button, the Agents page's, the core's own, its comments cut down, with no room added (10-30); 1,317,705 with a Claude account added from a setup-token (sfss5362 on X): the sign-in's Use a setup-token instead…, its sheet, and its account row's magpie only, the provider editor's account rows, the core's own editor, its comments cut down, with no room added (10-30); back to 1,315,316 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, loaded when one is asked for (signAsk, 10-30); 1,315,479 with the provider editor lining its Advanced up with its fields (the owner: 高级这个折叠按钮为什么在一个前不着村后不着店的位置?) and a refresh on each of its accounts (在这里也要加上手动刷新用量的按钮), the core's own editor, with no room added (10-31); 1,315,603 with About's Log row, the path of the log the app writes and an Open for its folder (rayem1w on X), in app.js, its comment cut to one line, with no room added (10-31); 1,316,781 with a provider's model listed by an id of the user's (zeewell on X), the provider editor's Names & levels Listed as box beside Same as, the core's own editor, with no room added (10-31); 1,316,874 with a package manager's magpie (the AUR's magpie-bin) naming the command that updates it in Settings' Version row and lighting no Update pill (shuhai on Discord), the core's own update row, which the tray panel reads too, its comments cut to one line, with no room added (10-31) - coreScriptBudget = 1_539_856 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29); 1,532,459 with a provider editor's account rows on one line each, First or Make first at its right end and the settings that aren't set under ⋯ (the owner), the core's own editor, in app.js, which stays in its budget with its comments cut down, with no room added (10-29); 1,532,602 with a plugin's README waiting for its bird to land on three lines before it goes in, however soon it came (the owner, 10-30), in plugins.js, with no room added; 1,536,357 with Switch accounts only on the Agents row (the owner on X), in app.js, with no room added (10-30); 1,537,034 with a plugin's README read once shown at once, with no bird, when its page opens again and read again behind it, the last 20 kept (the owner), in plugins.js, with no room added (10-30); 1,539,423 with a Claude account added from a setup-token (sfss5362 on X), in app.js, with no room added (10-30); 1,538,975 with purposes.js written as compact JSON by genpurposes and the MCP tool purpose in it, 448 bytes less in all (ferock on Discord), lowered to it (10-30); 1,536,586 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, lowered by the 2,389 the setup-token raised it (10-30); 1,536,631 with the 45 bytes b62fa332f added to app.js (Send requests unmasked for subscriptions and plugin providers too) without a raise, with no room added (10-31); 1,537,356 with Settings › Models › Replies › Claude Code's interactive mode, a row beside Short Claude system prompt (the owner), in app.js, with no room added (10-31); Long conversations in Codex's row naming the config.toml keys Codex reads before it, with Take it out, and the window magpie tells Codex for the model it runs (zgjfjfl on Discord) raised it to 1,537,669, and it is back under 1,537,356 with the key list and the window's size written by the server (codexKeysText, tokensSize) and the row's words cut, no raise (10-31); 1,538,554 with the same two, with no room added (10-31); 1,538,678 with About's Log row (rayem1w on X), with no room added (10-31); 1,539,856 with a model's Listed as id (zeewell on X), in app.js, with no room added (10-31); Tuned for you's Codex row offering the advice to background compaction (herman_hong on Discord) and a package manager's magpie naming its command (shuhai on Discord) took it to 1,541,798, and the release notes' dialogs (What's new, the update's ask) moved out to whatsnew.js, loaded when one opens, brought it back under 1,539,856, no raise (10-31) + appScriptBudget = 1_317_497 // app.js: 1,198,239 after Usage left (P2); 1,218,098 with the 10-15 fixes to pages still in the core; 1,232,466 with the provider editor's Advanced fold and every dialog holding its place, the core's own (10-16); 1,250,533 with the quota refresh kept through redraws, the core's own since the tray panel draws it too, plus 1.5% (#2397); 1,269,083 with Free first's option in the provider editor's ROUTINGS, which the Routing page reads too, plus 1.5%; 1,272,726 with the Providers page drawing its last list at once (#1519), the core's page, and the Routing trace's account names read without Object.entries (#1481), plus 1.5%; a dialog growing out of the row that opened it and folding back into it, the core's own since every page's dialogs open through it (10-20); Codex's and Claude Code's own settings moved from Settings into the agent's row on the Agents page, the core's own since the tray panel and the window both draw them (10-20); 1,314,432 with Settings › Privacy's record of what was masked (its summary, the records view and the local model's controls), which belongs to Settings, the core's own, plus 1.5%; 1,336,481 with a provider's Names & levels saying Provider in model names is Settings' and opening it there (joe), and Settings' Image recognition saying where a custom provider's model is marked (nexnull), both in the core's own pages, with no room added (10-23); 1,337,633 with Settings › Models › Replies' Intent classifier timeout (#2934, reyoung), Settings' own row, drawn by waitRow, which the Image generation timeout's row now shares, with no room added; 1,337,735 with the provider editor's link naming a partner's page by its own host (siteHost) instead of usemagpie.ai's /go link, the core's own editor, with no room added (10-23); 1,338,084 with Check in now saying what the press came to (claimed +credits, already today, not available yet) where it said "refreshed" (#3326), the check-in row the tray panel draws too, the core's own, with no room added (10-23); 1,338,929 with a new partner's tile keeping a small dot until it is opened, in the add sheet, the core's own, with no room added (10-23); 1,343,324 with the sidebar's open-page row marked by one shape that moves on a spring (navTopGo), the window's own shell, which every page sits beside, with no room added (10-23); 1,343,465 with a dialog kept centred while its content comes in, until it is pressed (holdModal, every page's dialogs), the core's own, with no room added (10-24); 1,317,486 with what masking did moved out to Insights › Masking (plugins/redact), the budget lowered to it (10-24); 1,321,336 with Codex's one subagent model, its card's square saying plainly what each choice does and a row with a name in its sheet, where two squares read alike (the owner), the Agents page's, which the tray panel draws too, the core's own, with no room added (10-24); 1,321,424 with Settings › Models' Image generation MCP server row beside Image recognition's (JonahFu on X), the two drawn by one helper (mcpRow), Settings' own, with no room added (10-25); 1,321,994 with a provider of the user's set never to rest for a limit (zoecats), the provider editor's Advanced row, the core's own editor, with no room added (10-25); 1,322,289 with Settings › Privacy's Keep a key's form under Mask secrets (Charles Cao on X), Settings' own row, with no room added (10-25); 1,322,537 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,323,401 with the tray panel drawing its last allowances at once and asking for them beside the state (#3160, #3134), the tray panel's, the core's own, and the 4 bytes 84c50f032 added, with no room added (10-25); 1,326,105 with many releases' notes merged into one list by kind, each line with its version (the owner), in the update sheet and What's new, with no room added (10-25); 1,321,319 with Settings › Observability moved out to its plugin (plugins/otel/page.js) and its Langfuse setup there (an X user), the budget lowered to it (10-26); a quota card whose window is used but names no reset no longer saying "Not used yet" (windy on Discord) raised it to 1,321,347, and back to 1,321,319 with Settings' model pickers sharing one row helper (modelOpt) where six kept their own copy, no raise (10-26); 1,325,845 with every slow page's skeletons getting magpie's bird hopping bar to bar (skelBird, the owner after the Plugins page's README), one bird for the window over whatever page or dialog is loading, the core's own, with no room added (10-26); 1,310,129 with Settings › Network and sharing's gateway rows (its port, bare ids, local network, allowed addresses, web pages) moved out to the gateway plugin (plugins/gateway/settings.js), the budget lowered to it (10-27); 1,310,269 with Test models naming the first model that failed and its error in the status line, where it said only how many (ysm119 on Discord), the provider editor's, the core's own, with no room added (10-27); 1,310,460 with Settings › About's Website row linking usemagpie.ai (the owner), Settings' own row, with no room added (10-27); 1,309,669 with a pool's Stop at the caps and Check usage near a cap ticks under a provider's accounts (plugins#349), the core's own editor, its account rows' Remove and add rows each drawn by one helper (forgetOf, addRow), with no room added (10-28); 1,311,681 with Install another agent on the Agents page naming the agents Plugins has (More in Plugins) and opening Plugins at its Agents (the owner), the Agents page's, the core's own, with no room added (10-28); 1,311,735 with More in Plugins in sight while Install another agent is folded (the owner), with no room added (10-29); 1,313,704 with a window whose WebKit scrolls under wheels it never tells of (macOS 13) remembered once seen, a scroll at rest then waiting 120ms for a second the same way within 80ms before it is put back, kept for a late wheel to give back (waitsBack), and a load landing under the wheel keeping the reader's way (backAfterLoad, issennknight), the window's own scroll guard, with no room added (10-29); back to 1,311,735 with Settings › Models › Web search's rows (renderSearch, renderSearcher, the search APIs' keys) moved out to the search plugin (plugins/search/settings.js), app.js 1,292,527 after it, not lowered further since what is left plus 1.5% is over it (#4133, 10-29); 1,315,316 with the Agents row of a Claude Code or Codex not connected saying the account it is signed in to and switching it to another (Switch accounts only, the owner on X), in place of the failover line's ChatGPT accounts button, the Agents page's, the core's own, its comments cut down, with no room added (10-30); 1,317,705 with a Claude account added from a setup-token (sfss5362 on X): the sign-in's Use a setup-token instead…, its sheet, and its account row's magpie only, the provider editor's account rows, the core's own editor, its comments cut down, with no room added (10-30); back to 1,315,316 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, loaded when one is asked for (signAsk, 10-30); 1,315,479 with the provider editor lining its Advanced up with its fields (the owner: 高级这个折叠按钮为什么在一个前不着村后不着店的位置?) and a refresh on each of its accounts (在这里也要加上手动刷新用量的按钮), the core's own editor, with no room added (10-31); 1,315,603 with About's Log row, the path of the log the app writes and an Open for its folder (rayem1w on X), in app.js, its comment cut to one line, with no room added (10-31); 1,316,781 with a provider's model listed by an id of the user's (zeewell on X), the provider editor's Names & levels Listed as box beside Same as, the core's own editor, with no room added (10-31); 1,316,874 with a package manager's magpie (the AUR's magpie-bin) naming the command that updates it in Settings' Version row and lighting no Update pill (shuhai on Discord), the core's own update row, which the tray panel reads too, its comments cut to one line, with no room added (10-31); 1,317,497 with Settings › Sync's Kept on this computer row, an agent's fields set back here after a sync changed them, with Follow the others (hayden4608 on Discord), Settings' own row, with no room added (10-31) + coreScriptBudget = 1_540_479 // every core script: 1,358,034 after Usage left; 1,380,003 with them; 1,405,937 with the fold; 1,426,102 with 10-16's core work (the GitHub list loading, the move to plugins, Settings › Long conversations), plus 1.5% (#2612); 1,447,368 with loadBack, the window's one state read per return, which every page needs and so is the core's own (1,446,845 before it, 155 bytes under), plus 1.5%; OpenCode Zen's card saying OpenCode tells no key its balance adds ~390 bytes inside it; 1,472,589 with the dialog that grows out of its row and the agents' own settings in their rows, on main's 10-20 core work (the Providers page's last list, the Routing trace's names), plus 1.5% (10-20); 1,506,192 with Settings › Privacy's record of what was masked, plus 1.5%; 1,529,393 with the Intent classifier timeout row (#2934), with no room added; 1,529,495 with the editor's partner link host, with no room added; 1,529,844 with Check in now's press summary (#3326), with no room added; 1,530,689 with the new partner tile's dot, with no room added; 1,535,084 with the sidebar's spring, with no room added; 1,549,478 with the context window card's map (tiles by tokens, the default look, the block grid a switch away) and its text view showing an inline image, in context.js, which the Routing page draws as well as Usage, so the core's own, with no room added (10-24); 1,550,768 with a usage card's refresh opening after its text (#840's card, which the tray panel draws too), the Add key spinner, and a dialog kept centred while its content comes in, with no room added (10-24); 1,524,789 with what masking did moved out to Insights › Masking, lowered to it; 1,528,525 with Codex's one subagent model, with no room added (10-24); 1,528,972 with the Image generation MCP server row (JonahFu on X), with no room added (10-25); 1,529,542 with the limit-rest row (zoecats), with no room added (10-25); 1,529,837 with Keep a key's form (Charles Cao on X), with no room added (10-25); 1,530,050 with no Codex squares beside its named settings rows (the owner), with no room added (10-25); 1,530,631 with a plugin's page growing to its README on the dialog's spring instead of in one jump (the owner), the Plugins page's, in plugins.js, with no room added (10-25); 1,533,445 with the context map counting its tokens on as a live request grows, a tile pointed at keeping its tip, a tool's gathered results saying how many and the small files their folder (the owner, after flohoeller's map on X), in context.js, which the Routing page draws as well as Usage, and the 4 bytes 84c50f032 added to app.js (Settings' Version row) without a raise, with no room added (10-25); 1,534,312 with the tray panel's last allowances drawn at once (#3160, #3134), with no room added (10-25); 1,537,016 with many releases' notes merged into one list by kind (the owner), in app.js, with no room added (10-25); 1,542,244 with a plugin's README loading under magpie's bird bouncing down its lines instead of pulsing bars (the owner), the Plugins page's, in plugins.js, with no room added (10-26); 1,542,418 with a page plugin's sidebar tab coming and going as it is installed, switched on or off, or removed, instead of on the Plugins page's next load (the owner), in plugins.js, with no room added (10-26); 1,537,645 with Settings › Observability moved out to plugins/otel, lowered to it (10-26); 1,537,673 with a used window with no reset not "Not used yet" (windy on Discord), and back to 1,537,645 with Settings' model pickers sharing modelOpt (10-26); 1,541,967 with every slow page's skeletons getting magpie's bird (skelBird, the owner), in app.js, the README's bird sharing its drawing and styles, with no room added (10-26); 1,526,251 with Settings' gateway rows moved out to plugins/gateway/settings.js, lowered to it (10-27); 1,526,391 with Test models naming the first failed model and its error (ysm119 on Discord), in app.js, with no room added (10-27); 1,526,556 with About's Website row (the owner), in app.js, with no room added (10-27); 1,526,500 with a pool's cap ticks (plugins#349), in app.js, with no room added (10-28); 1,527,245 with About's Open-source licenses row and dialog (the owner), in app.js, with no room added (10-28); 1,528,076 with the Partners heading's light (the owner), in app.js, with no room added (10-28); 1,530,449 with Install another agent's More in Plugins row (the owner), in app.js, and Plugins opening at its Agents, in plugins.js, with no room added (10-28); 1,530,807 with layout.js measuring the scrollbar into --bar, which every page's right padding takes off so its sides match (the owner), the window's own shell, with no room added (10-28); 1,530,861 with More in Plugins in sight while Install another agent is folded (the owner), in app.js, with no room added (10-29); 1,532,830 with waitsBack and backAfterLoad (issennknight, macOS 13), the window's own scroll guard, in app.js, with no room added (10-29); the context map's tile wording (a4e929212) and Cindy's Add magpie (628ac36fc) had taken the core over it, and Web search's rows moved out to plugins/search/settings.js brought it back to 1,530,861 (#4133, 10-29); 1,532,459 with a provider editor's account rows on one line each, First or Make first at its right end and the settings that aren't set under ⋯ (the owner), the core's own editor, in app.js, which stays in its budget with its comments cut down, with no room added (10-29); 1,532,602 with a plugin's README waiting for its bird to land on three lines before it goes in, however soon it came (the owner, 10-30), in plugins.js, with no room added; 1,536,357 with Switch accounts only on the Agents row (the owner on X), in app.js, with no room added (10-30); 1,537,034 with a plugin's README read once shown at once, with no bird, when its page opens again and read again behind it, the last 20 kept (the owner), in plugins.js, with no room added (10-30); 1,539,423 with a Claude account added from a setup-token (sfss5362 on X), in app.js, with no room added (10-30); 1,538,975 with purposes.js written as compact JSON by genpurposes and the MCP tool purpose in it, 448 bytes less in all (ferock on Discord), lowered to it (10-30); 1,536,586 with the setup-token sheet and Copilot's GHE.com one moved out to signsheets.js, lowered by the 2,389 the setup-token raised it (10-30); 1,536,631 with the 45 bytes b62fa332f added to app.js (Send requests unmasked for subscriptions and plugin providers too) without a raise, with no room added (10-31); 1,537,356 with Settings › Models › Replies › Claude Code's interactive mode, a row beside Short Claude system prompt (the owner), in app.js, with no room added (10-31); Long conversations in Codex's row naming the config.toml keys Codex reads before it, with Take it out, and the window magpie tells Codex for the model it runs (zgjfjfl on Discord) raised it to 1,537,669, and it is back under 1,537,356 with the key list and the window's size written by the server (codexKeysText, tokensSize) and the row's words cut, no raise (10-31); 1,538,554 with the same two, with no room added (10-31); 1,538,678 with About's Log row (rayem1w on X), with no room added (10-31); 1,539,856 with a model's Listed as id (zeewell on X), in app.js, with no room added (10-31); Tuned for you's Codex row offering the advice to background compaction (herman_hong on Discord) and a package manager's magpie naming its command (shuhai on Discord) took it to 1,541,798, and the release notes' dialogs (What's new, the update's ask) moved out to whatsnew.js, loaded when one opens, brought it back under 1,539,856, no raise (10-31); 1,540,479 with Settings › Sync's Kept on this computer row (hayden4608 on Discord), in app.js, with no room added (10-31) ) func TestCoreScriptBudget(t *testing.T) { diff --git a/internal/gui/tests/sync-own-fields.test.cjs b/internal/gui/tests/sync-own-fields.test.cjs new file mode 100644 index 000000000..31033fbb7 --- /dev/null +++ b/internal/gui/tests/sync-own-fields.test.cjs @@ -0,0 +1,111 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// An agent's field set back on a computer after a sync changed it stays that +// computer's (hayden4608 on Discord: two computers on one GitHub sync, each +// wanting its own Codex model). Settings → Sync names the fields kept here, +// in the page's language, and Follow the others gives them back to sync: +// it asks the server once, and the row goes with the fields. A sync with no +// such fields, or with agents' models off, shows no row. In every language, +// Chromium and WebKit, at a narrow width with nothing wider than the page. +// The API is faked; nothing is synced. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); + +const assets = path.resolve(__dirname, "../assets"); + +function serve(lang, sync, posts) { + const settings = { + theme: "light", lang, tray: "panel", version: "test", dir: "/tmp/magpie", + gateway: "http://127.0.0.1:3425", visionModels: [], imageGenModels: [], + fx: { rate: 7.2, stale: false }, + }; + return async (route) => { + const request = route.request(); + const pathname = new URL(request.url()).pathname; + const json = (data) => route.fulfill({ json: data }); + if (pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` }); + if (pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (pathname === "/api/state") return json({ agents: [], profiles: [], settings }); + if (pathname === "/api/settings") return json(settings); + if (pathname === "/api/usage/quotas") return json([]); + if (pathname === "/api/groups") return json({ groups: [], models: [] }); + if (pathname === "/api/plugins") return json({ plugins: [] }); + if (pathname === "/api/davsync") return json(sync); + if (pathname === "/api/davsync/follow") { + posts.push("follow"); + const { own, ...rest } = sync; + return json(rest); + } + if (pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, pathname === "/" ? "index.html" : pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + return route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const words = { + en: { title: "Kept on this computer", follow: "Follow the others", field: "Codex model" }, + zh: { title: "仅本机保留", follow: "跟随其他电脑", field: "Codex 模型" }, + "zh-TW": { title: "僅本機保留", follow: "跟隨其他電腦", field: "Codex 模型" }, + ja: { title: "このコンピュータだけで保持", follow: "ほかのコンピュータに合わせる", field: "Codex のモデル" }, + de: { title: "Nur auf diesem Computer", follow: "Den anderen folgen", field: "Codex: Modell" }, +}; + +const base = () => ({ on: true, kind: "github", url: "github://alice/private/team", passwordSet: true, passphraseSet: true, + keys: true, agents: true, library: true, auto: 3, last: new Date().toISOString() }); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + const open = async (t, lang, sync, posts, width = 900) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage(); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, sync, posts)); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-sync-own-fields.png`), fullPage: true }); + } + await browser.close(); + }); + page.setDefaultTimeout(5000); + await page.goto("http://magpie.test/"); + await page.locator("#prefs").click(); + await openPart(page, "sync"); + await page.locator("#syncList .row").first().waitFor({ state: "visible" }); + return { page, errors }; + }; + + for (const lang of Object.keys(words)) { + const w = words[lang]; + test(`${engine} ${lang}: the fields kept on this computer are named, and follow the others on a click`, async (t) => { + const posts = []; + const sync = { ...base(), own: [{ agent: "Codex", field: "model" }] }; + const { page, errors } = await open(t, lang, sync, posts, 420); + const row = page.locator("#syncList .row", { has: page.locator(".sync-own") }); + await row.waitFor({ state: "visible" }); + assert.equal((await row.locator(".name").textContent()).trim(), w.title); + assert.ok((await row.locator(".sync-own").textContent()).includes(w.field), `names ${w.field}`); + const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); + assert.ok(over <= 0, `nothing wider than the page (${over}px over)`); + const y = await page.evaluate(() => document.scrollingElement.scrollTop); + await row.getByRole("button", { name: w.follow, exact: true }).click(); + await row.waitFor({ state: "detached" }); + assert.deepEqual(posts, ["follow"], "asked the server once"); + assert.equal(await page.evaluate(() => document.scrollingElement.scrollTop), y, "the click moved nothing"); + assert.deepEqual(errors, [], "nothing threw"); + }); + } + + for (const [name, sync] of [["no fields kept", base()], ["agents' models off", { ...base(), agents: false, own: [{ agent: "Codex", field: "model" }] }]]) { + test(`${engine}: ${name} shows no row for them`, async (t) => { + const { page, errors } = await open(t, "en", sync, []); + assert.equal(await page.locator("#syncList .sync-own").count(), 0); + assert.equal(await page.getByText("Kept on this computer").count(), 0); + assert.deepEqual(errors, [], "nothing threw"); + }); + } +}