diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md index 630de493b..e8d13dc41 100644 --- a/docs/subsystems/provider-plugins.md +++ b/docs/subsystems/provider-plugins.md @@ -58,7 +58,7 @@ A plugin can press its vendor's daily check-in (签到) itself: its `auth` hook The hook returns `{outcome, credit?, streak?, message?, until?}`. `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; for an outcome not in the list the reason names what the plugin answered, before its own message (`the plugin answered "yes": …`), so a plugin's wording isn't read as magpie's. `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. An `inactive` or `ineligible` result with a `message` shows it beside the fixed label ("No check-in event now · ") on the card, where it wraps rather than ends in "…", in Settings' check-in line and in `magpie accounts checkin`; the TUI's narrow cell says `c` says why, and `c`'s flash carries it (plugins#304). Without a message the label reads alone. -[`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. A `done`, `inactive` or `ineligible` answered before noon Beijing (`checkinSureHour`) for an account magpie hasn't seen claim that Beijing day is provisional (`provisional`, #3326): a vendor whose day turns at UTC midnight (08:00 Beijing) or later still answers yesterday's "already" at 00:00, and magpie took it for today's and never asked again. The loop asks it again 30 minutes after the answer, until a claim or an answer from noon on, so at most 24 more asks a day and none once magpie claims; a press (`soon`) asks it again at once, whatever the hour, since the vendor's answer is what the press is for. A claim stamps `Claimed`, carried over while later answers that day say done, so a done after magpie's own claim is settled. Such a record is sent with `again: true` (`shown`, never kept), and the card, Settings, TUI and CLI say the vendor said already checked in and magpie asks again later, not "Checked in today", and the card keeps *Check in now*. A vendor whose day turns after noon Beijing (a US day) is not covered. The Qoder and Qoder CN plugins are the exception, as magpie's own Qoder check-in is (`recheck`, `pluginRechecks`, #2696): a campaign can open mid-day (Qoder CN's ran 10:00 to 09:59 the next day), so the loop asks again 30 minutes after the last answer whatever it was, and *Check in now* asks at once, and their card keeps *Check in now* for an `inactive` result. Every other plugin keeps the day's result. A plugin whose vendor's day turns at another hour says when in `until` (an RFC 3339 time or epoch milliseconds; `host.js` passes it on as RFC 3339, `plugin.Checkin.Until`), kept as the record's `ValidUntil`: the answer is settled only until then, whatever its outcome (`settled`), the loop wakes then rather than at its next 30-minute look (`wbCheckinLoop.tick`), and an early `done` that says it isn't provisional, since the vendor said when its day turns. Qoder's daily credits open at 10:00 UTC+8 and close at 09:59 the next day (its `/me/campaigns` `startAt`/`endAt`); the Qoder plugins from 0.2.43 answer `until` a minute past the next opening, so a check-in before 10:00, which claims or meets the day before's campaign, is asked again at 10:01, not up to half an hour later (sdytman on Discord). Times are compared as instants, so the machine's zone doesn't matter. Results are kept in `plugin-checkin.json` by `provider|` (`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|` 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; until then no plugin account is checked in, and each says why (`readCheckins`, as for every vendor's check-in file). 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:"`), 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}`). The press says what it came to, a count per kind (`checkinPressSaid`, #3326): claimed now with the credits, already checked in today, not available yet (`inactive`, `ineligible`, or an `again` answer), to check in in the vendor's own app, failed; a result is claimed now only when it carries `asked` (`Asked`, sent but never kept), so an account claimed earlier today counts as already. `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`. Under each vendor's switch in Settings, a *Check in now* row checks one account in once (`checkinNowRow`, drawn by [`checkinnow.js`](../../internal/gui/assets/checkinnow.js), loaded when Settings draws a vendor's check-in so it weighs nothing on the core; `POST /api/usage/checkin-account {by, key}`, `provider.CheckInAccount`; xiaowu_95660 on Discord): the same `checkinNow` press, with `only` set to that account's key, so no other account is asked or reported, and the account is asked even while its switch is off, which the press leaves as it is. With two or more accounts the button opens the app menu to pick one. The row says what came of it: checked in with the credit and streak, already checked in today, not eligible or no check-in event with the vendor's message, check in in the vendor's own app, or the failure. It reads the Usage cards again but doesn't draw Settings again under the button. +[`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. A `done`, `inactive` or `ineligible` answered before noon Beijing (`checkinSureHour`) for an account magpie hasn't seen claim that Beijing day is provisional (`provisional`, #3326): a vendor whose day turns at UTC midnight (08:00 Beijing) or later still answers yesterday's "already" at 00:00, and magpie took it for today's and never asked again. The loop asks it again 30 minutes after the answer, until a claim or an answer from noon on, so at most 24 more asks a day and none once magpie claims; a press (`soon`) asks it again at once, whatever the hour, since the vendor's answer is what the press is for. A claim stamps `Claimed`, carried over while later answers that day say done, so a done after magpie's own claim is settled. Such a record is sent with `again: true` (`shown`, never kept), and the card, Settings, TUI and CLI say the vendor said already checked in and magpie asks again later, not "Checked in today", and the card keeps *Check in now*. A vendor whose day turns after noon Beijing (a US day) is not covered. The Qoder, Qoder CN and ZCode plugins are the exception, as magpie's own Qoder check-in is (`recheck`, `pluginRechecks`, #2696, plugins#503): a campaign or gift plan can open mid-day (Qoder CN's ran 10:00 to 09:59 the next day), so the loop asks again 30 minutes after the last answer, whatever it was but a `captcha` or `own-app`, which waits on the user in the vendor's app and stands for the day (asked again, ZCode's claim only answered 3007 again, plugins#503), and *Check in now* asks at once, and their card keeps *Check in now* for an `inactive` result. Every other plugin keeps the day's result. A plugin whose vendor's day turns at another hour says when in `until` (an RFC 3339 time or epoch milliseconds; `host.js` passes it on as RFC 3339, `plugin.Checkin.Until`), kept as the record's `ValidUntil`: the answer is settled only until then, whatever its outcome (`settled`), the loop wakes then rather than at its next 30-minute look (`wbCheckinLoop.tick`), and an early `done` that says it isn't provisional, since the vendor said when its day turns. Qoder's daily credits open at 10:00 UTC+8 and close at 09:59 the next day (its `/me/campaigns` `startAt`/`endAt`); the Qoder plugins from 0.2.43 answer `until` a minute past the next opening, so a check-in before 10:00, which claims or meets the day before's campaign, is asked again at 10:01, not up to half an hour later (sdytman on Discord). Times are compared as instants, so the machine's zone doesn't matter. Results are kept in `plugin-checkin.json` by `provider|` (`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|` 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; until then no plugin account is checked in, and each says why (`readCheckins`, as for every vendor's check-in file). 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:"`), 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}`). The press says what it came to, a count per kind (`checkinPressSaid`, #3326): claimed now with the credits, already checked in today, not available yet (`inactive`, `ineligible`, or an `again` answer), to check in in the vendor's own app, failed; a result is claimed now only when it carries `asked` (`Asked`, sent but never kept), so an account claimed earlier today counts as already. `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`. Under each vendor's switch in Settings, a *Check in now* row checks one account in once (`checkinNowRow`, drawn by [`checkinnow.js`](../../internal/gui/assets/checkinnow.js), loaded when Settings draws a vendor's check-in so it weighs nothing on the core; `POST /api/usage/checkin-account {by, key}`, `provider.CheckInAccount`; xiaowu_95660 on Discord): the same `checkinNow` press, with `only` set to that account's key, so no other account is asked or reported, and the account is asked even while its switch is off, which the press leaves as it is. With two or more accounts the button opens the app menu to pick one. The row says what came of it: checked in with the credit and streak, already checked in today, not eligible or no check-in event with the vendor's message, check in in the vendor's own app, or the failure. It reads the Usage cards again but doesn't draw Settings again under the button. 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. diff --git a/internal/provider/checkin.go b/internal/provider/checkin.go index c66c2fc4e..6d9168c1e 100644 --- a/internal/provider/checkin.go +++ b/internal/provider/checkin.go @@ -3,9 +3,9 @@ package provider // A daily check-in, whichever vendor's: WorkBuddy's (workbuddy_checkin.go) // and Trae CN's (trae_checkin.go). Each account in use is checked in once // a Beijing day, except Qoder's campaigns and ZCode's gift plans, -// rechecked every 30 minutes, -// and an answer that may be the vendor's day before (provisional, #3326), -// asked again every 30 minutes until a claim or an answer from noon on. +// rechecked every 30 minutes but for a captcha or own-app answer, which +// waits on the user, and an answer that may be the vendor's day before +// (provisional, #3326), asked again every 30 minutes until a claim or an answer from noon on. // A press asks the vendor again for a done, inactive or ineligible one. // What came of it is kept in the vendor's file by its key for reuse // (see workbuddy_checkin.go for when a failure is tried again). @@ -108,7 +108,13 @@ func (c checkiner) checkinNow(ctx context.Context, soon bool) []WorkBuddyCheckin settled = now.Sub(prev.At) < wbCheckinEvery } if c.recheck { - settled = settled && !soon && now.Sub(prev.At) < wbCheckinEvery + // a captcha or own-app answer waits on the user, in the + // vendor's app, so the loop leaves it for the day: asked + // again every 30 minutes, ZCode's claim only answered 3007 + // again, and the reporter's accounts went on to 3012 + // (plugins#503). A press still asks. + waits := prev.Outcome == CheckinCaptcha || prev.Outcome == CheckinOwnApp + settled = settled && !soon && (waits || now.Sub(prev.At) < wbCheckinEvery) if prev.Checked() && !prev.ValidUntil.IsZero() { settled = settled && now.Before(prev.ValidUntil) } diff --git a/internal/provider/plugin_checkin_test.go b/internal/provider/plugin_checkin_test.go index 74648e333..32cced5ef 100644 --- a/internal/provider/plugin_checkin_test.go +++ b/internal/provider/plugin_checkin_test.go @@ -545,6 +545,49 @@ func TestPluginCheckinQoderRechecksCampaigns(t *testing.T) { } } +// plugins#503 (MiniFullC): a ZCode account whose claim asked for the +// app's captcha was asked again every 30 minutes, the claim posted and +// answered 3007 each time, six more times in one evening. A captcha, or +// an own-app answer, waits on the user, so the loop leaves it for the +// day under a recheck too; a press still asks, and the next day asks. +func TestPluginCheckinRecheckLeavesCaptcha(t *testing.T) { + for _, id := range []string{"zcode", "qoder"} { + for _, first := range []string{CheckinCaptcha, CheckinOwnApp} { + t.Run(id+"/"+first, func(t *testing.T) { + claudeHome(t) + now := time.Date(2026, 11, 3, 14, 16, 0, 0, time.UTC) // 22:16 Beijing + outcome, calls := first, 0 + p := pluginCheckinCounter(id, &outcome, &calls) + run := func(press bool) WorkBuddyCheckin { + t.Helper() + got := p.checkiner(func() time.Time { return now }).checkinNow(context.Background(), press) + if len(got) != 1 { + t.Fatalf("at %s: %+v", now, got) + } + return got[0] + } + run(false) + outcome = CheckinClaimed + for _, step := range []time.Duration{31 * time.Minute, 31 * time.Minute, 30 * time.Minute} { + now = now.Add(step) + if r := run(false); r.Outcome != first || calls != 1 { + t.Fatalf("loop at %s: %+v after %d asks; want %s kept after 1", now.In(beijing).Format(time.TimeOnly), r, calls, first) + } + } + if r := run(true); r.Outcome != CheckinClaimed || calls != 2 { + t.Fatalf("press: %+v after %d asks", r, calls) + } + outcome = first + now = time.Date(2026, 11, 4, 14, 0, 0, 0, time.UTC) // the next Beijing day + run(false) + if calls != 3 { + t.Fatalf("the next day: %d asks, want 3", calls) + } + }) + } + } +} + // Every other plugin's check-in is settled for the Beijing day by a claim, // or by a done, inactive or ineligible answered from noon Beijing on: the // loop doesn't ask again after 30 minutes (#2696 changes Qoder's, plugins#503 ZCode's).