Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

provider: a plugin's daily check-in reaches every sign-in, also two that share a display name (plugins#254)

yetone62a1df8010a2
diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md
index b6cfbf4ae..fd9f0747f 100644
--- a/docs/subsystems/provider-plugins.md
+++ b/docs/subsystems/provider-plugins.md
@@ -44,7 +44,7 @@ A plugin can press its vendor's daily check-in (签到) itself: its `auth` hook
The hook returns `{outcome, credit?, streak?, message?}`. `outcome` is one of `claimed` (checked in now), `done` (already in today), `ineligible`, `inactive` (no check-in event now), `captcha` or `failed`. A throw, or an outcome not in that list, is `failed` with the reason. `captcha` means the vendor wants a captcha: magpie never solves one, and says "check in in its own app" instead. A plugin must not solve captchas either.
-[`plugin_checkin.go`](../../internal/provider/plugin_checkin.go) runs these through the same `checkiner` as the built-in check-ins ([`checkin.go`](../../internal/provider/checkin.go)): each signed-in, in-use account once a Beijing day, the first look 2 minutes after start and then every 30 minutes, a `failed` asked again after 30 minutes, every other outcome settled for the day. Results are kept in `plugin-checkin.json` by `provider|account`; a failure is recorded as failed and never resets an account, a key or a previous day's result. Each account's Usage card has the check-in row (`checkinBy: "plugin:<provider>"`), and Settings → Usage has a Plugins tab with a Daily check-in switch per provider (`settings.PluginCheckins`, `POST /api/settings/plugin-checkin {provider, on}`; *Check in now* is `POST /api/usage/plugin-checkin {provider}`). `magpie accounts checkin` and `c` on the TUI's Usage page include them. Every check-in, built-in or a plugin's, also skips an account listed in `settings.CheckinOff` by its file key (#1902): `checkinNow` asks nothing for it, by the loop or a press, `CheckinAccounts()` lists each account with its own `on` for Settings (`checkinAccounts`, a row each under the vendor's switch when it has two or more, `POST /api/settings/checkin-account {key, on}`), and its card carries `checkinOff`.
+[`plugin_checkin.go`](../../internal/provider/plugin_checkin.go) runs these through the same `checkiner` as the built-in check-ins ([`checkin.go`](../../internal/provider/checkin.go)): each signed-in, in-use account once a Beijing day, the first look 2 minutes after start and then every 30 minutes, a `failed` asked again after 30 minutes, every other outcome settled for the day. Results are kept in `plugin-checkin.json` by `provider|<sign-in key>` (`pluginCheckinKey`: the key `plugin-auth.json` keeps the sign-in under, `autoclaw` or `autoclaw#x1y2z3`), never by the display name: two sign-ins can share a name (AutoClaw's default can't be changed), and keyed by it only the first of them was ever checked in, by the loop or *Check in now* (plugins#254). The sign-in key holds over a refresh and over signing in to the same account again (`settle` in `host.js` puts it back under its key); a sign-in made after one was signed out the same day may take the freed key, and with it that day's result. An entry kept by `provider|<display name>` before then is carried over once the plugin's accounts are listed (`adoptLegacyPluginCheckins`): a check-in goes to the first sign-in in use of that name, the one the old key asked, and only to it, so its namesakes are asked and none twice; an `Off` in `settings.CheckinOff` goes to every sign-in of that name, since none of them was checked in while it was off. A `plugin-checkin.json` that can't be read or parsed is left as it is and carried over once it reads. A failure is recorded as failed and never resets an account, a key or a previous day's result. Each account's Usage card has the check-in row (`checkinBy: "plugin:<provider>"`), and Settings → Usage has a Plugins tab with a Daily check-in switch per provider (`settings.PluginCheckins`, `POST /api/settings/plugin-checkin {provider, on}`; *Check in now* is `POST /api/usage/plugin-checkin {provider}`). `magpie accounts checkin` and `c` on the TUI's Usage page include them. Every check-in, built-in or a plugin's, also skips an account listed in `settings.CheckinOff` by its file key (#1902): `checkinNow` asks nothing for it, by the loop or a press, `CheckinAccounts()` lists each account with its own `on` for Settings (`checkinAccounts`, a row each under the vendor's switch when it has two or more, `POST /api/settings/checkin-account {key, on}`), and its card carries `checkinOff`.
The switch is off by default. For a provider whose vendor magpie checked in through the plugin's fetch before (WorkBuddy, Trae CN, MiniMax Code, Qoder), it follows that vendor's existing switch until set on its own, and magpie's own check-in leaves that provider's accounts to the plugin (`pluginChecksIn`), so an account is never checked in twice.
@@ -192,7 +192,7 @@ Gateway parity tests in [`plugin_parity_test.go`](../../internal/gateway/plugin_
[`plugin_decide_test.go`](../../internal/gateway/plugin_decide_test.go) runs the fake plugin (`FAKE_DECIDE`) with a decision API: its marked and `jev-*` models are classifiers and not offered to agents, chat to one is refused, a group saves one as classifier, not beside a chat model, and a group of decision models alone, and each classifier's question reaches the fake vendor at `/v1/systemone` through the plugin's fetch. With `FAKE_DECIDE=models` the marks without `decide` change nothing.
-[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
+[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside; `TestPluginCheckinTellsSignInsOfOneNameApart` signs in four accounts under two names, two of each (plugins#254), and checks each is checked in, kept, carded and switched off on its own, and `TestPluginCheckinCarriesOverDisplayNameEntries` upgrades a file and an `Off` kept by display name. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
[`plugin_options_test.go`](../../internal/plugin/plugin_options_test.go) loads `testdata/options` in a real host: which declared options are kept and how they are capped, the user's value over the default at start, and a change read by the plugin after `SetProviderOptions` without a restart. [`plugin_option_api_test.go`](../../internal/gui/plugin_option_api_test.go) covers the endpoint, a bad key, and a Settings save keeping the values. `plugin-options.test.cjs` covers the editor in Chromium and WebKit, 1100 and 420 wide, in every language.
diff --git a/internal/plugin/testdata/fake/index.js b/internal/plugin/testdata/fake/index.js
index dc83d038c..256a99c70 100644
--- a/internal/plugin/testdata/fake/index.js
+++ b/internal/plugin/testdata/fake/index.js
@@ -217,7 +217,8 @@ export const FakePlugin = async ({ client }) => ({
}
},
// $FAKE_CHECKIN: the plugin presses the daily check-in itself, each
- // press written as a line of the account's key to that file, and the
+ // press written as a line of the account's key to that file (a signed-in
+ // account's name/uid, so two of one name tell apart), and the
// answer said by the key: ck-claim gives 50 on a 3-day streak, ck-done
// is in already, ck-captcha is asked a captcha, ck-throw can't reach
// the vendor, ck-odd answers no outcome magpie knows
@@ -226,7 +227,7 @@ export const FakePlugin = async ({ client }) => ({
checkin: async (getAuth) => {
const a = await getAuth()
const fs = await import("node:fs")
- fs.appendFileSync(process.env.FAKE_CHECKIN, (a.key ?? a.accountId ?? "") + "\n")
+ fs.appendFileSync(process.env.FAKE_CHECKIN, (a.key ?? (a.uid ? a.accountId + "/" + a.uid : a.accountId) ?? "") + "\n")
switch (a.key) {
case "ck-claim":
return { outcome: "claimed", credit: 50, streak: 3 }
diff --git a/internal/provider/plugin_checkin.go b/internal/provider/plugin_checkin.go
index 41bae04c3..fc2643856 100644
--- a/internal/provider/plugin_checkin.go
+++ b/internal/provider/plugin_checkin.go
@@ -9,11 +9,16 @@ package provider
// from magpie's own check-in through its fetch (WorkBuddy, Trae CN,
// MiniMax Code, Qoder), so an account is never checked in twice.
//
-// What came of it is kept in plugin-checkin.json by provider and account.
+// What came of it is kept in plugin-checkin.json by provider and sign-in
+// (pluginCheckinKey).
import (
"context"
+ "encoding/json"
+ "log"
+ "os"
"path/filepath"
+ "slices"
"sort"
"sync"
"time"
@@ -33,9 +38,31 @@ var pluginCheckinMu sync.Mutex
type pluginCheckinAcct struct {
User string
On bool
- key string // provider|account
- card string
- do func(context.Context) WorkBuddyCheckin
+ key string // pluginCheckinKey
+ // legacy is the account's entry before plugins#254,
+ // pluginCheckinLegacyKey
+ legacy string
+ card string
+ do func(context.Context) WorkBuddyCheckin
+}
+
+// pluginCheckinKey is a plugin sign-in's entry in plugin-checkin.json and
+// settings.CheckinOff: the provider and the key plugin-auth.json keeps the
+// sign-in under ("autoclaw", "autoclaw#x1y2z3"). Two sign-ins never share
+// it, and it holds while the sign-in does: a refresh writes the same key,
+// and signing in to an account already signed in goes back to its key
+// (host.js settle). Its display name (AccountID) is not the account: two
+// AutoClaw sign-ins share a default name the user can't change, and keyed
+// on it only the first of them was ever checked in (plugins#254).
+func pluginCheckinKey(id, login string) string { return id + "|" + login }
+
+// pluginCheckinLegacyKey is what pluginCheckinKey was before plugins#254:
+// the provider and the account's display name, else its sign-in key.
+func pluginCheckinLegacyKey(id string, a plugin.Account) string {
+ if a.AccountID != "" {
+ return id + "|" + a.AccountID
+ }
+ return pluginCheckinKey(id, a.Key)
}
// pluginCheckinProvider is a plugin's provider that checks in, and its
@@ -57,12 +84,8 @@ var pluginCheckinProviders = func() []pluginCheckinProvider {
card := PluginID(pp.ID)
for _, l := range pluginLogins(pp) {
acct := l.acct.Key
- who := l.acct.AccountID
- if who == "" {
- who = acct
- }
id := pp.ID
- p.accounts = append(p.accounts, pluginCheckinAcct{User: l.User, On: l.On, key: id + "|" + who, card: card,
+ p.accounts = append(p.accounts, pluginCheckinAcct{User: l.User, On: l.On, key: pluginCheckinKey(id, acct), legacy: pluginCheckinLegacyKey(id, l.acct), card: card,
do: func(ctx context.Context) WorkBuddyCheckin {
c, err := plugin.AccountCheckin(ctx, id, acct)
if err != nil {
@@ -75,9 +98,149 @@ var pluginCheckinProviders = func() []pluginCheckinProvider {
out = append(out, p)
}
}
+ adoptLegacyPluginCheckins(out)
return out
}
+// pluginCheckinAdopted are the legacy entries (pluginCheckinLegacyKey),
+// by the check-in file they were looked for in, that
+// adoptLegacyPluginCheckins has carried over or found nothing kept under,
+// so it reads the files once for each; under pluginCheckinMu.
+var pluginCheckinAdopted = map[[2]string]bool{}
+
+// adoptLegacyPluginCheckins carries what was kept under each account's
+// entry before plugins#254 (its provider and display name) over to its
+// entry now (its sign-in), so an upgrade neither checks an account in
+// twice in a day nor loses the user's own Off. Kept under a name two
+// sign-ins share, it is:
+//
+// - a check-in, in plugin-checkin.json: the first of them in use, in
+// the order the check-in lists them, the one the old key's check-in
+// asked (it skipped the rest), and only that one: the others were
+// never asked, so they are asked now. The entry goes once carried.
+// - an account left out, in settings.CheckinOff: each of them. The user
+// switched that name off, and none of its sign-ins was checked in
+// since; one switched on only by the upgrade would be checked in
+// against the user's choice.
+//
+// A file that can't be read or parsed is left for later as it is, and the
+// entries are carried again once it reads.
+func adoptLegacyPluginCheckins(ps []pluginCheckinProvider) {
+ pluginCheckinMu.Lock()
+ defer pluginCheckinMu.Unlock()
+ path := pluginCheckinPath()
+ // an entry a sign-in keeps now is never taken for an old one
+ now := map[string]bool{}
+ for _, p := range ps {
+ for _, a := range p.accounts {
+ now[a.key] = true
+ }
+ }
+ // each legacy entry's heirs, those in use first: the old check-in
+ // skipped an account not in use before it took the key
+ heirs := map[string][]string{}
+ var order []string
+ for _, inUse := range []bool{true, false} {
+ for _, p := range ps {
+ for _, a := range p.accounts {
+ if a.On != inUse || a.legacy == "" || now[a.legacy] || pluginCheckinAdopted[[2]string{path, a.legacy}] {
+ continue
+ }
+ if _, ok := heirs[a.legacy]; !ok {
+ order = append(order, a.legacy)
+ }
+ heirs[a.legacy] = append(heirs[a.legacy], a.key)
+ }
+ }
+ }
+ if len(order) == 0 {
+ return
+ }
+ checkins := adoptLegacyCheckinFile(path, order, heirs)
+ off := adoptLegacyCheckinOff(heirs)
+ if checkins && off {
+ for _, l := range order {
+ pluginCheckinAdopted[[2]string{path, l}] = true
+ }
+ }
+}
+
+// adoptLegacyCheckinFile gives each legacy entry of the check-in file at
+// path to its first heir that has none of its own, and drops it; it says
+// whether the file is as it should be now.
+func adoptLegacyCheckinFile(path string, order []string, heirs map[string][]string) bool {
+ b, err := os.ReadFile(path)
+ if os.IsNotExist(err) {
+ return true
+ }
+ if err != nil {
+ log.Printf("plugin check-in: %v", err)
+ return false
+ }
+ st := map[string]WorkBuddyCheckin{}
+ if err := json.Unmarshal(b, &st); err != nil {
+ log.Printf("plugin check-in: %s: %v", path, err)
+ return false
+ }
+ changed := false
+ for _, l := range order {
+ r, ok := st[l]
+ if !ok {
+ continue
+ }
+ if _, has := st[heirs[l][0]]; !has {
+ st[heirs[l][0]] = r
+ }
+ delete(st, l)
+ changed = true
+ }
+ if !changed {
+ return true
+ }
+ out, err := json.MarshalIndent(st, "", " ")
+ if err == nil {
+ err = writePrivate(path, append(out, '\n'))
+ }
+ if err != nil {
+ log.Printf("plugin check-in: %v", err)
+ return false
+ }
+ return true
+}
+
+// adoptLegacyCheckinOff puts every heir of a legacy entry in
+// settings.CheckinOff in its place; it says whether the settings are as
+// they should be now.
+func adoptLegacyCheckinOff(heirs map[string][]string) bool {
+ s, err := settings.LoadChecked()
+ if err != nil {
+ return false
+ }
+ if !slices.ContainsFunc(s.CheckinOff, func(k string) bool { _, ok := heirs[k]; return ok }) {
+ return true
+ }
+ err = settings.EditCheckinOff(func(off []string) []string {
+ var out []string
+ for _, k := range off {
+ ks, ok := heirs[k]
+ if !ok {
+ ks = []string{k}
+ }
+ for _, k := range ks {
+ if !slices.Contains(out, k) {
+ out = append(out, k)
+ }
+ }
+ }
+ return out
+ })
+ if err != nil {
+ log.Printf("plugin check-in: %v", err)
+ return false
+ }
+ return true
+}
+
// pluginChecksIn says whether pp's plugin presses the check-in itself:
// magpie's own check-in through its fetch leaves its accounts to it.
func pluginChecksIn(pp plugin.Provider) bool { return pp.Checkin }
diff --git a/internal/provider/plugin_checkin_test.go b/internal/provider/plugin_checkin_test.go
index 804e81799..593c6eb64 100644
--- a/internal/provider/plugin_checkin_test.go
+++ b/internal/provider/plugin_checkin_test.go
@@ -2,6 +2,7 @@ package provider
import (
"context"
+ "encoding/json"
"os"
"path/filepath"
"slices"
@@ -224,3 +225,256 @@ func TestPluginCheckinTakesOverTheVendors(t *testing.T) {
}
}
}
+
+// pluginCheckinTeams is the fake plugin with its own check-in, signed in
+// through its browser sign-in as each team (name/uid): the reporter's case
+// in plugins#254 is two AutoClaw display names with two sign-ins each,
+// told apart only by their uid. It says the file each press is written to,
+// as name@fake/uid, and each team's sign-in key.
+func pluginCheckinTeams(t *testing.T, teams ...string) (string, map[string]string) {
+ t.Helper()
+ presses := pluginCheckinSandbox(t)
+ for _, team := range teams {
+ st, err := StartPluginSignIn("fakeco", 1, map[string]string{"where": "work", "team": team})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := SubmitSignInCallback(st.ID, "good"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+ if _, err := plugin.Providers(ctx); err != nil {
+ t.Fatal(err)
+ }
+ keys := map[string]string{} // name@fake/uid → its sign-in's key
+ for k, a := range plugin.Auths("fakeco") {
+ id, _ := a["accountId"].(string)
+ uid, _ := a["uid"].(string)
+ keys[id+"/"+uid] = k
+ }
+ if len(keys) != len(teams) {
+ t.Fatalf("signed in as %v, want %d sign-ins", keys, len(teams))
+ }
+ return presses, keys
+}
+
+// pluginCheckinOn turns fakeco's daily check-in on.
+func pluginCheckinOn(t *testing.T) {
+ t.Helper()
+ s := settings.Load()
+ s.PluginCheckins = map[string]bool{"fakeco": true}
+ if err := settings.Save(s); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// pluginCards are a card for each of p's accounts, as the Usage page has.
+func pluginCards(p pluginCheckinProvider) []SubscriptionQuota {
+ var qs []SubscriptionQuota
+ for _, a := range p.accounts {
+ qs = append(qs, SubscriptionQuota{Provider: PluginID(p.ID), User: a.User})
+ }
+ return qs
+}
+
+// Two sign-ins of one plugin that share a display name are two accounts
+// to check in (plugins#254: four AutoClaw sign-ins under two default
+// names, which AutoClaw doesn't let the user change, and only the first of
+// each name was ever checked in, by the loop or Check in now). Each is
+// checked in once a day, kept, carded and switched off on its own.
+func TestPluginCheckinTellsSignInsOfOneNameApart(t *testing.T) {
+ presses, keys := pluginCheckinTeams(t, "A/u1", "A/u2", "B/u3", "B/u4")
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+ pluginCheckinOn(t)
+ ps := pluginCheckinProviders()
+ if len(ps) != 1 || len(ps[0].accounts) != 4 {
+ t.Fatalf("the plugins that check in: %+v", ps)
+ }
+ now := time.Date(2026, 10, 6, 10, 0, 0, 0, beijing)
+ loop := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return PluginCheckinOn(settings.Load(), id) }}
+ all := "A@fake/u1,A@fake/u2,B@fake/u3,B@fake/u4"
+ sorted := func(p []string) string { return strings.Join(slices.Sorted(slices.Values(p)), ",") }
+
+ if rs := loop.checkinNow(ctx, false); len(rs) != 4 || sorted(pressed(t, presses)) != all {
+ t.Fatalf("the loop: %+v, pressed %q", rs, pressed(t, presses))
+ }
+ // kept for each: nothing asked again that day
+ now = now.Add(time.Minute)
+ if rs := loop.checkinNow(ctx, false); len(rs) != 4 || len(pressed(t, presses)) != 4 {
+ t.Fatalf("a minute on: %+v, pressed %q", rs, pressed(t, presses))
+ }
+ st := readCheckins(pluginCheckinPath())
+ for who, k := range keys {
+ if r, ok := st[pluginCheckinKey("fakeco", k)]; !ok || r.Day != "2026-10-06" || r.Outcome != CheckinInactive {
+ t.Errorf("%s (%s) kept as %+v, ok %v; file %+v", who, k, r, ok, st)
+ }
+ }
+ if len(st) != 4 {
+ t.Errorf("plugin-checkin.json holds %d entries, want 4: %+v", len(st), st)
+ }
+ // Settings lists each, and each card says today's
+ if pcs := PluginCheckins(); len(pcs) != 1 || len(pcs[0].Checkins) != 4 {
+ t.Fatalf("PluginCheckins = %+v", pcs)
+ }
+ for i, q := range WithCheckins(pluginCards(ps[0])) {
+ if !q.Checkins || q.Checkin == nil || q.Checkin.Day != "2026-10-06" {
+ t.Fatalf("card %d (%s): %+v", i, q.User, q.Checkin)
+ }
+ }
+ // each its own row in Settings, and one switched off is left out
+ var rows []string
+ for _, a := range CheckinAccounts() {
+ if a.By == "plugin:fakeco" {
+ rows = append(rows, a.Key)
+ }
+ }
+ if len(rows) != 4 {
+ t.Fatalf("Settings' rows: %q", rows)
+ }
+ s := settings.Load()
+ s.CheckinOff = []string{pluginCheckinKey("fakeco", keys["A@fake/u2"])}
+ if err := settings.Save(s); err != nil {
+ t.Fatal(err)
+ }
+ // Check in now, the next day: each but the one switched off
+ now = time.Date(2026, 10, 7, 9, 0, 0, 0, beijing)
+ press := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return id == "fakeco" }}
+ press.checkinNow(ctx, true)
+ if p := sorted(pressed(t, presses)[4:]); p != "A@fake/u1,B@fake/u3,B@fake/u4" {
+ t.Fatalf("Check in now with A@fake/u2 off pressed %q", p)
+ }
+ for _, q := range WithCheckins(pluginCards(ps[0])) {
+ if q.CheckinOff != (q.User == userOf(ps[0], keys["A@fake/u2"])) {
+ t.Fatalf("card %s: off %v", q.User, q.CheckinOff)
+ }
+ }
+}
+
+// userOf is the name the account signed in under key is shown by.
+func userOf(p pluginCheckinProvider, key string) string {
+ for _, a := range p.accounts {
+ if a.key == pluginCheckinKey(p.ID, key) {
+ return a.User
+ }
+ }
+ return ""
+}
+
+// An upgrade from a plugin-checkin.json kept by display name (before
+// plugins#254) checks no account in twice and keeps the user's own Off: a
+// name checked in today is carried to the one sign-in the old key asked,
+// the first in use, so only its namesake is asked; a name switched off
+// stays off for each sign-in of it; another vendor's Off is left alone.
+func TestPluginCheckinCarriesOverDisplayNameEntries(t *testing.T) {
+ presses, keys := pluginCheckinTeams(t, "A/u1", "A/u2", "B/u3", "B/u4")
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+ now := time.Date(2026, 10, 6, 10, 0, 0, 0, beijing)
+ legacy := map[string]WorkBuddyCheckin{
+ "fakeco|A@fake": {Day: "2026-10-06", At: now.Add(-time.Hour), Outcome: CheckinClaimed, Credit: 400},
+ "fakeco|B@fake": {Day: "2026-10-06", At: now.Add(-time.Hour), Outcome: CheckinClaimed, Credit: 400},
+ // another plugin's, whose accounts aren't signed in: left as kept
+ "other|C": {Day: "2026-10-05", At: now.Add(-25 * time.Hour), Outcome: CheckinDone},
+ }
+ b, _ := json.Marshal(legacy)
+ if err := os.WriteFile(pluginCheckinPath(), b, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ s := settings.Load()
+ s.PluginCheckins = map[string]bool{"fakeco": true}
+ s.CheckinOff = []string{"workbuddy|123", "fakeco|B@fake"}
+ if err := settings.Save(s); err != nil {
+ t.Fatal(err)
+ }
+
+ ps := pluginCheckinProviders()
+ if len(ps) != 1 || len(ps[0].accounts) != 4 {
+ t.Fatalf("the plugins that check in: %+v", ps)
+ }
+ // the sign-in of A the old key asked: the first of A's in use
+ var heir, namesake string
+ for _, a := range ps[0].accounts {
+ if a.legacy == "fakeco|A@fake" && a.On {
+ if heir == "" {
+ heir = a.key
+ } else if namesake == "" {
+ namesake = a.key
+ }
+ }
+ }
+ if heir == "" || namesake == "" {
+ t.Fatalf("A's sign-ins: %+v", ps[0].accounts)
+ }
+ st := readCheckins(pluginCheckinPath())
+ if r, ok := st[heir]; !ok || r.Outcome != CheckinClaimed || r.Credit != 400 || r.Day != "2026-10-06" {
+ t.Fatalf("A's check-in went to %s as %+v (ok %v): %+v", heir, r, ok, st)
+ }
+ if _, ok := st[namesake]; ok {
+ t.Fatalf("A's check-in was carried to both its sign-ins: %+v", st)
+ }
+ if _, ok := st["fakeco|A@fake"]; ok {
+ t.Fatalf("A's old entry was kept: %+v", st)
+ }
+ if _, ok := st["other|C"]; !ok {
+ t.Fatalf("another plugin's entry went: %+v", st)
+ }
+ off := settings.Load().CheckinOff
+ want := []string{"workbuddy|123", pluginCheckinKey("fakeco", keys["B@fake/u3"]), pluginCheckinKey("fakeco", keys["B@fake/u4"])}
+ if !slices.Equal(slices.Sorted(slices.Values(off)), slices.Sorted(slices.Values(want))) {
+ t.Fatalf("CheckinOff = %q, want %q", off, want)
+ }
+
+ // the loop asks only A's namesake: the heir is in, B's are off
+ loop := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return PluginCheckinOn(settings.Load(), id) }}
+ loop.checkinNow(ctx, false)
+ var who string
+ for w, k := range keys {
+ if pluginCheckinKey("fakeco", k) == namesake {
+ who = w
+ }
+ }
+ if p := pressed(t, presses); len(p) != 1 || p[0] != who {
+ t.Fatalf("after the upgrade pressed %q, want only %s", p, who)
+ }
+ // and nothing is carried again, or asked again, on the next look
+ pluginCheckinProviders()
+ loop.checkinNow(ctx, false)
+ if p := pressed(t, presses); len(p) != 1 {
+ t.Fatalf("a second look pressed %q", p)
+ }
+ for _, a := range CheckinAccounts() {
+ if a.By == "plugin:fakeco" && a.On == strings.HasPrefix(a.User, "B@fake") {
+ t.Fatalf("Settings' row %+v: B's should be off, A's on", a)
+ }
+ }
+}
+
+// A plugin-checkin.json that doesn't parse is unknown: nothing is carried
+// over or written over, and it is carried once it reads.
+func TestPluginCheckinCarriesNothingOverAnUnreadableFile(t *testing.T) {
+ path := filepath.Join(claudeHome(t), "plugin-checkin.json")
+ order, heirs := []string{"fakeco|A"}, map[string][]string{"fakeco|A": {"fakeco|fakeco", "fakeco|fakeco#x1"}}
+ bad := []byte(`{"fakeco|A": {"day": "2026-10-06",`)
+ if err := os.WriteFile(path, bad, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if adoptLegacyCheckinFile(path, order, heirs) {
+ t.Fatal("a file that doesn't parse was taken as carried over")
+ }
+ if b, _ := os.ReadFile(path); string(b) != string(bad) {
+ t.Fatalf("the file was written over: %s", b)
+ }
+ if err := os.WriteFile(path, []byte(`{"fakeco|A": {"day": "2026-10-06", "outcome": "claimed"}}`), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if !adoptLegacyCheckinFile(path, order, heirs) {
+ t.Fatal("not carried once the file reads")
+ }
+ st := readCheckins(path)
+ if _, ok := st["fakeco|fakeco"]; !ok || len(st) != 1 {
+ t.Fatalf("carried as %+v", st)
+ }
+}
diff --git a/internal/settings/settings.go b/internal/settings/settings.go
index 50077408a..eabe5807e 100644
--- a/internal/settings/settings.go
+++ b/internal/settings/settings.go
@@ -221,7 +221,10 @@ type Settings struct {
// CheckinOff are the accounts left out of their vendor's daily
// check-in while it is on (#1902), each by its entry in the vendor's
// check-in file: "<site or provider>|<account id>" ("workbuddy|<uid>",
- // "trae-cn|<uid>", a plugin's "<provider>|<account>").
+ // "trae-cn|<uid>", a plugin's "<provider>|<sign-in key>", e.g.
+ // "autoclaw|autoclaw#x1y2z3"; before plugins#254 a plugin's was
+ // "<provider>|<display name>", which provider.adoptLegacyPluginCheckins
+ // carries over).
CheckinOff []string `json:"checkinOff,omitempty"`
// MemberModel has a reply's model name the routing group's member
// that answered, as magpie's provider/model id (workbuddy/glm-5.3-flash),
@@ -1222,6 +1225,24 @@ func SetGatewayConversations(on bool) error {
return save(s, true)
}
+// EditCheckinOff changes CheckinOff alone, as edit returns it from what the
+// file holds now, so a save elsewhere from an older snapshot isn't undone.
+// A settings file that can't be read is left as it is, with the error.
+func EditCheckinOff(edit func([]string) []string) error {
+ fileMu.Lock()
+ defer fileMu.Unlock()
+ s, err := loadChecked()
+ if err != nil {
+ return err
+ }
+ off := edit(slices.Clone(s.CheckinOff))
+ if len(off) == 0 {
+ off = nil
+ }
+ s.CheckinOff = off
+ return save(s, false)
+}
+
// SetRedactModel turns the local masking model on or off, on its own, as
// Settings → Privacy does once the model is downloaded.
func SetRedactModel(on bool) error {