diff --git a/AGENTS.md b/AGENTS.md index 9b56ac4aa..6cd92ce63 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,6 +31,7 @@ the same job: | Subscription | id | Plugin (npm) | Mover | | --- | --- | --- | --- | +| Antigravity | `antigravity` | `@magpie-community/opencode-antigravity-auth` | `internal/provider/migrate_antigravity.go` | | Command Code | `commandcode-plan` | `@magpie-community/opencode-commandcode-auth` | `internal/provider/migrate_side.go` | | Cursor | `cursor` | `@magpie-community/opencode-cursor-auth` | `internal/provider/migrate_side.go` | | Devin | `devin` | `@magpie-community/opencode-devin-auth` | `internal/provider/migrate_side.go` | @@ -76,8 +77,11 @@ Two cases decide it: nothing; a line over the Providers list says so, with why and a Move (`providers.unmoved`, `unmovedLine` in app.js). With no row of its own, the Add sheet leaves it to the Plugins page (`unusedSub`). Every - subscription in the table above is retired (10-17); gates ask - `provider.PluginServes(id)` (moved or retired). + subscription in the table above is retired (10-17) except Antigravity, + which is moved but whose built-in code is still there until every + account has gone over (11-10); gates ask `provider.PluginServes(id)` + (moved or retired). Gemini CLI (`gemini`) and the agy agent stay built + in. The plugin does everything: sign-in, refresh, models, requests, usage and errors. It runs in the plugin host (`internal/plugin`). The built-ins' diff --git a/internal/provider/antigravity_pool.go b/internal/provider/antigravity_pool.go index eb93bcd35..19029d94e 100644 --- a/internal/provider/antigravity_pool.go +++ b/internal/provider/antigravity_pool.go @@ -1,5 +1,15 @@ package provider +// PLUGIN-SERVED (see AGENTS.md): Antigravity ("antigravity") is a +// deprecated built-in subscription served by its plugin, +// @magpie-community/opencode-antigravity-auth, once moved onto it +// (provider.Moved). A moved one's sign-ins, models, requests and usage are +// all the plugin's, never this code's (only the move, in migrate*.go, still +// reads its accounts). A fix here alone doesn't reach those users; fix the +// plugin (github.com/magpie-community/plugins, packages/antigravity) and +// raise the mover's min in internal/provider/migrate_antigravity.go. +// Gemini CLI ("gemini") and the agy agent stay built in. + import ( "context" "fmt" diff --git a/internal/provider/migrate_antigravity.go b/internal/provider/migrate_antigravity.go new file mode 100644 index 000000000..1d16446bc --- /dev/null +++ b/internal/provider/migrate_antigravity.go @@ -0,0 +1,70 @@ +package provider + +import ( + "encoding/json" + "errors" + "strings" + "time" +) + +// Antigravity's accounts on @magpie-community/opencode-antigravity-auth: +// the plugin keeps a Google sign-in as an oauth entry whose refresh is +// "|", with the access token and its expiry beside +// it and the email as its accountId. An account the built-in had no +// project for yet goes with none, and the plugin asks Code Assist for it +// (loadCodeAssist, onboardUser) as the built-in did. +func init() { + movers["antigravity"] = &mover{ + pkg: "@magpie-community/opencode-antigravity-auth", + min: "0.1.0", // the built-in's sign-in, project, models, request shaping, errors and usage pools, ported + agents: []string{"antigravity"}, + out: func() ([]Moving, error) { + var out []Moving + for _, l := range googleLogins("antigravity") { + a := l.acct.auth + if a.RefreshToken == "" { + continue + } + out = append(out, Moving{User: l.User, First: l.Active, On: l.On, Lapsed: l.Lapsed != "", Plan: l.Plan, Auth: map[string]any{ + "type": "oauth", + "refresh": a.RefreshToken + "|" + a.Project, + "access": a.AccessToken, + "expires": a.Expiry, + "accountId": l.User, + }}) + } + return out, nil + }, + back: func(ls []savedLogin, user string, auth map[string]any) ([]savedLogin, string, error) { + rt, project, _ := strings.Cut(str(auth["refresh"]), "|") + if rt == "" { + return ls, "", errors.New("Antigravity: an unreadable plugin sign-in") + } + if user == "" { + user = str(auth["accountId"]) + } + if user == "" { + return ls, "", errors.New("Antigravity: a plugin sign-in with no account") + } + i := backInto(&ls, "antigravity", user) + var a googleAuth + _ = json.Unmarshal(ls[i].Auth, &a) + a.RefreshToken, a.AccessToken = rt, str(auth["access"]) + if e, ok := auth["expires"].(float64); ok { + a.Expiry = int64(e) + } + if project != "" { + a.Project = project + } + b, err := json.Marshal(a) + if err != nil { + return ls, "", err + } + ls[i].Auth, ls[i].Lapsed, ls[i].Refused, ls[i].Seen = b, "", "", time.Now().UTC().Truncate(time.Second) + if project != "" { + ls[i].Project = project + } + return ls, ls[i].User, nil + }, + } +} diff --git a/internal/provider/migrate_antigravity_test.go b/internal/provider/migrate_antigravity_test.go new file mode 100644 index 000000000..222aaa7b1 --- /dev/null +++ b/internal/provider/migrate_antigravity_test.go @@ -0,0 +1,71 @@ +package provider + +import ( + "encoding/json" + "testing" +) + +// Antigravity's accounts go to its plugin as "|" +// with the access token, its expiry and the email; one with no project yet +// goes with none for the plugin to ask Code Assist. Back, a renewed sign-in +// is written into the account it came from, its project kept when the +// plugin's has none, and one signed in since is added. +func TestAntigravityMover(t *testing.T) { + claudeHome(t) + auth := func(a googleAuth) json.RawMessage { + b, _ := json.Marshal(a) + return b + } + saveLogins(t, + savedLogin{Agent: "antigravity", User: "a@x.com", Auth: auth(googleAuth{RefreshToken: "ra", AccessToken: "aa", Expiry: 1900000000000, Project: "proj-a"}), On: true, First: true, Plan: "Google AI Pro"}, + savedLogin{Agent: "antigravity", User: "b@x.com", Auth: auth(googleAuth{RefreshToken: "rb"}), Lapsed: "refused", Refused: revokedPrefix + "rb"}, + // Gemini CLI's accounts are no Antigravity's + savedLogin{Agent: "gemini", User: "g@x.com", Auth: auth(googleAuth{RefreshToken: "rg"}), On: true}) + ForgetAccounts() + + ms := movingOf(t, "antigravity") + if len(ms) != 2 { + t.Fatalf("moving %+v", ms) + } + a := ms["a@x.com"] + if !a.First || !a.On || a.Lapsed || a.Plan != "Google AI Pro" || a.Auth["type"] != "oauth" || a.Auth["refresh"] != "ra|proj-a" || + a.Auth["access"] != "aa" || a.Auth["expires"] != int64(1900000000000) || a.Auth["accountId"] != "a@x.com" { + t.Fatalf("a: %+v", a) + } + if b := ms["b@x.com"]; b.First || !b.Lapsed || b.Auth["refresh"] != "rb|" || b.Auth["accountId"] != "b@x.com" { + t.Fatalf("b: %+v", b) + } + + // a renewed, with the project the plugin found for it + ls, user, err := movers["antigravity"].back(readLogins(), "a@x.com", map[string]any{"type": "oauth", "refresh": "ra2|proj-a2", "access": "aa2", "expires": float64(1950000000000), "accountId": "a@x.com"}) + if err != nil || user != "a@x.com" { + t.Fatalf("back a: %q %v", user, err) + } + var got googleAuth + l := loginOf(t, ls, "antigravity", "a@x.com") + if json.Unmarshal(l.Auth, &got) != nil || got.RefreshToken != "ra2" || got.AccessToken != "aa2" || got.Expiry != 1950000000000 || got.Project != "proj-a2" || l.Project != "proj-a2" || l.Plan != "Google AI Pro" { + t.Fatalf("a back: %+v %s", l, l.Auth) + } + // b back with no project: the one it had stays, and it is lapsed no more + ls, _, err = movers["antigravity"].back(ls, "b@x.com", map[string]any{"type": "oauth", "refresh": "rb2|", "access": "ab2", "accountId": "b@x.com"}) + if err != nil { + t.Fatal(err) + } + if l := loginOf(t, ls, "antigravity", "b@x.com"); l.Lapsed != "" || l.Refused != "" || func() error { got = googleAuth{}; return json.Unmarshal(l.Auth, &got) }() != nil || got.RefreshToken != "rb2" || got.Project != "" { + t.Fatalf("b back: %+v %s", l, l.Auth) + } + // one signed in through the plugin since, named by its accountId + n := len(ls) + ls, user, err = movers["antigravity"].back(ls, "", map[string]any{"type": "oauth", "refresh": "rc|proj-c", "access": "ac", "accountId": "c@x.com"}) + if err != nil || user != "c@x.com" || len(ls) != n+1 { + t.Fatalf("back c: %q %v %d", user, err, len(ls)) + } + if l := loginOf(t, ls, "antigravity", "c@x.com"); l.Project != "proj-c" { + t.Fatalf("c back: %+v", l) + } + for _, bad := range []map[string]any{{"type": "oauth", "refresh": "|p", "accountId": "d@x.com"}, {"type": "oauth", "refresh": "rd"}} { + if _, _, err := movers["antigravity"].back(ls, "", bad); err == nil { + t.Fatalf("back took %v", bad) + } + } +}