diff --git a/docs/subsystems/provider-plugins.md b/docs/subsystems/provider-plugins.md index bbfe04398..894358e9e 100644 --- a/docs/subsystems/provider-plugins.md +++ b/docs/subsystems/provider-plugins.md @@ -46,7 +46,7 @@ The hook returns `{outcome, credit?, streak?, message?}`. `outcome` is one of `c 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. -Trae CN plugins without `auth.checkin` use [`trae_checkin.go`](../../internal/provider/trae_checkin.go) through the plugin's fetch: `/status`, then `/claim` while the check-in is on and today's isn't in. A claim answered 9074 (当前参与用户太多,请稍后再试) is saved as `own-app`, settled for the Beijing day like any answer other than `failed`: Trae CN pays check-in credits only to a device its own app registered, so neither the loop nor Check in now claims again that day, and the card, Settings, TUI and CLI say to check in in the Trae CN app (#808). 9074 on `/status`, and every other code, keep their previous handling. `own-app` is not a plugin hook outcome. +Trae CN plugins without `auth.checkin` use [`trae_checkin.go`](../../internal/provider/trae_checkin.go) through the plugin's fetch: `/status`, then `/claim` while the check-in is on and today's isn't in. A claim answered 9074 (当前参与用户太多,请稍后再试) is saved as `own-app`, settled for the Beijing day like any answer other than `failed`: no retry ever got past it (#808), so neither the loop nor Check in now claims again that day, and the card, Settings, TUI and CLI say Trae CN refused the check-in (9074) and to check in in the Trae CN app, not that Trae pays only its own app, which Buddy Switch disproves (#1920). Since plugin 0.2.14 the account this machine's Trae CN desktop client is signed in as sends the client's own device id (the `iCubeAuthInfo://icube-dc:` key of its `storage.json`, read only) with its check-in; every other account keeps its own device, and none is made up or rotated (#1705). 9074 on `/status`, and every other code, keep their previous handling. `own-app` is not a plugin hook outcome. WorkBuddy's check-in ([`workbuddy_checkin.go`](../../internal/provider/workbuddy_checkin.go), built-in or through the plugin's fetch) tells a 401 apart. WorkBuddy's gateway answers a token it refuses with a bare HTML 401, which the card said only as "Unauthorized" and retried every 30 minutes. On a 401 from `/v2/billing/meter/checkin-activity-status` or `/daily-checkin`, the account's credits (`/billing/meter/get-user-resource-summary`) are read with the same headers: when they read, the sign-in is good and the check-in alone refuses magpie (WorkBuddy's own app sends its check-in, and only that, with an `X-Device-Token` from its security SDK), so it is saved as `own-app` for the day; when they don't, it is `failed` with "sign in to it again". diff --git a/internal/cli/accounts_cli.go b/internal/cli/accounts_cli.go index 0f4519a68..79a49796f 100644 --- a/internal/cli/accounts_cli.go +++ b/internal/cli/accounts_cli.go @@ -775,13 +775,14 @@ func checkinWorkBuddy(asJSON bool) error { case provider.CheckinCaptcha: fmt.Println(muted.Render("·"), r.User, muted.Render(strings.TrimSpace("asks for a captcha: check in in its own app "+r.Msg))) case provider.CheckinOwnApp: - // Trae CN's 9074 (#808): it pays only its own app; WorkBuddy's - // check-in answered 401 while the sign-in works + // Trae CN's 9074 (#808): Trae CN refused the claim (#1920); + // WorkBuddy's check-in answered 401 while the sign-in works + if r.By == "trae" { + fmt.Println(muted.Render("·"), r.User, muted.Render(provider.TraeRefusedWords)) + break + } name := r.Vendor - switch r.By { - case "trae": - name = "Trae CN" - case "": + if r.By == "" { name = "WorkBuddy" } fmt.Println(muted.Render("·"), r.User, muted.Render(name+" only gives check-in credits to its own app; check in in the "+name+" app")) diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index bb0fe6c5a..9677d7732 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -16776,9 +16776,12 @@ function checkinRow(q, first, subs) { text = t("Asks for a captcha; check in in its own app") + (r.msg ? " · " + r.msg : ""); break; case "own-app": - // the vendor pays only its own app (Trae CN's 9074, #808): not - // tried again today - text = t("{name} only gives check-in credits to its own app; check in in the {name} app", { name: checkinVendorName(r, q.name) }); + // to be done in the vendor's own app, not tried again today; + // Trae CN's 9074 (#808) says Trae refused it, which is what is + // known, not that only its app is paid (#1920) + text = r.by === "trae" + ? t("Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app") + : t("{name} only gives check-in credits to its own app; check in in the {name} app", { name: checkinVendorName(r, q.name) }); break; default: kind = "bad"; @@ -21452,7 +21455,9 @@ function wbCheckinLine(r) { case "captcha": return t("{user} is asked for a captcha; check in in the app", { user: r.user }); case "own-app": - return t("{user}: {name} only gives check-in credits to its own app; check in in the {name} app", { user: r.user, name: checkinVendorName(r) }); + return r.by === "trae" + ? t("{user}: Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app", { user: r.user }) + : t("{user}: {name} only gives check-in credits to its own app; check in in the {name} app", { user: r.user, name: checkinVendorName(r) }); default: return t("{user} couldn't check in, tried again later", { user: r.user }); } diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 1ee9e50ab..8ae451721 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1060,6 +1060,8 @@ const I18N = { "Asks for a captcha; check in in its own app": "需要验证码,请在它自己的 App 里签到", "{name} only gives check-in credits to its own app; check in in the {name} app": "{name} 只给自己的客户端发签到积分,请在 {name} App 里签到", "{user}: {name} only gives check-in credits to its own app; check in in the {name} app": "{user}:{name} 只给自己的客户端发签到积分,请在 {name} App 里签到", + "Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "Trae CN 拒绝了这次签到(9074 当前参与用户太多),请在 Trae CN App 里签到", + "{user}: Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "{user}:Trae CN 拒绝了这次签到(9074 当前参与用户太多),请在 Trae CN App 里签到", "{user} is asked for a captcha; check in in the app": "{user} 需要验证码,请在 App 里签到", "Has the {name} plugin check each signed-in account in once a day": "每天让 {name} 插件给每个已登录的账号签到一次", "On: magpie checks each WorkBuddy (China) account in once a day, as Settings' Daily check-in does. Click to turn it off.": "已开启:每天为每个 WorkBuddy 国内版账号签到一次,与设置中的「每日自动签到」为同一开关。点击关闭。", @@ -4672,6 +4674,8 @@ const I18N = { "Asks for a captcha; check in in its own app": "需要驗證碼,請在它自己的 App 裡簽到", "{name} only gives check-in credits to its own app; check in in the {name} app": "{name} 只給自己的客戶端發簽到積分,請在 {name} App 裡簽到", "{user}: {name} only gives check-in credits to its own app; check in in the {name} app": "{user}:{name} 只給自己的客戶端發簽到積分,請在 {name} App 裡簽到", + "Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "Trae CN 拒絕了這次簽到(9074 當前參與用戶太多),請在 Trae CN App 裡簽到", + "{user}: Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "{user}:Trae CN 拒絕了這次簽到(9074 當前參與用戶太多),請在 Trae CN App 裡簽到", "{user} is asked for a captcha; check in in the app": "{user} 需要驗證碼,請在 App 裡簽到", "Has the {name} plugin check each signed-in account in once a day": "每天讓 {name} 外掛給每個已登入的帳號簽到一次", "On: magpie checks each WorkBuddy (China) account in once a day, as Settings' Daily check-in does. Click to turn it off.": "已開啟:每天為每個 WorkBuddy 國內版帳號簽到一次,與設定中的「每日自動簽到」為同一開關。點選關閉。", @@ -8254,6 +8258,8 @@ const I18N = { "Asks for a captcha; check in in its own app": "CAPTCHA が必要です。公式アプリでチェックインしてください", "{name} only gives check-in credits to its own app; check in in the {name} app": "{name} はチェックインのクレジットを自社アプリにしか付与しません。{name} アプリでチェックインしてください", "{user}: {name} only gives check-in credits to its own app; check in in the {name} app": "{user}:{name} はチェックインのクレジットを自社アプリにしか付与しません。{name} アプリでチェックインしてください", + "Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "Trae CN がこのチェックインを拒否しました(9074:参加ユーザーが多すぎます)。Trae CN アプリでチェックインしてください", + "{user}: Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "{user}:Trae CN がこのチェックインを拒否しました(9074:参加ユーザーが多すぎます)。Trae CN アプリでチェックインしてください", "{user} is asked for a captcha; check in in the app": "{user} は CAPTCHA が必要です。アプリでチェックインしてください", "Has the {name} plugin check each signed-in account in once a day": "{name} プラグインがサインイン中の各アカウントを 1 日 1 回チェックインします", "On: magpie checks each WorkBuddy (China) account in once a day, as Settings' Daily check-in does. Click to turn it off.": "オン:magpie が各 WorkBuddy(中国版)アカウントを 1 日 1 回チェックインします。設定の「毎日のチェックイン」と同じです。クリックでオフにします。", @@ -11866,6 +11872,8 @@ const I18N = { "Asks for a captcha; check in in its own app": "Verlangt ein Captcha; in der eigenen App einchecken", "{name} only gives check-in credits to its own app; check in in the {name} app": "{name} vergibt Check-in-Credits nur an die eigene App; bitte in der {name}-App einchecken", "{user}: {name} only gives check-in credits to its own app; check in in the {name} app": "{user}: {name} vergibt Check-in-Credits nur an die eigene App; bitte in der {name}-App einchecken", + "Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "Trae CN hat diesen Check-in abgelehnt (9074: zu viele Teilnehmende); bitte in der Trae-CN-App einchecken", + "{user}: Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "{user}: Trae CN hat diesen Check-in abgelehnt (9074: zu viele Teilnehmende); bitte in der Trae-CN-App einchecken", "{user} is asked for a captcha; check in in the app": "{user} soll ein Captcha lösen; in der App einchecken", "Has the {name} plugin check each signed-in account in once a day": "Lässt das {name}-Plugin jedes angemeldete Konto einmal täglich einchecken", "On: magpie checks each WorkBuddy (China) account in once a day, as Settings' Daily check-in does. Click to turn it off.": "An: magpie checkt jedes WorkBuddy-Konto (China) einmal täglich ein, wie „Täglicher Check-in“ in den Einstellungen. Zum Ausschalten klicken.", diff --git a/internal/gui/tests/usage-checkin.test.cjs b/internal/gui/tests/usage-checkin.test.cjs index e61ec4168..147daaebe 100644 --- a/internal/gui/tests/usage-checkin.test.cjs +++ b/internal/gui/tests/usage-checkin.test.cjs @@ -190,10 +190,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(errors, []); }); - // #808: Trae CN answers a claim from magpie 9074 for good, since it - // pays only its own app; the card says to check in there, offers no + // #808: Trae CN answers a claim from magpie 9074 for the day; the card + // says Trae CN refused it, in Trae's words, and to check in in the + // Trae CN app, not that Trae pays only its app (#1920). It offers no // Check in now, and the Settings tab's line says the same. - test(`${engine} ${lang}: a Trae CN check-in only its own app gets says to check in in Trae CN`, async (t) => { + test(`${engine} ${lang}: a Trae CN check-in refused 9074 says Trae refused it and to check in in Trae CN`, async (t) => { const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); t.after(() => browser.close()); const page = await (await browser.newContext({ viewport: { width: 440, height: 900 }, reducedMotion: "reduce" })).newPage(); @@ -202,8 +203,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", page.on("pageerror", (e) => errors.push(e.message)); const own = { user: "hu", by: "trae", day: today, outcome: "own-app", msg: "当前参与用户太多,请稍后再试" }; const says = lang === "en" - ? "Trae CN only gives check-in credits to its own app; check in in the Trae CN app" - : "Trae CN 只给自己的客户端发签到积分,请在 Trae CN App 里签到"; + ? "Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app" + : "Trae CN 拒绝了这次签到(9074 当前参与用户太多),请在 Trae CN App 里签到"; await page.route("**/*", async (route) => { const url = new URL(route.request().url()); if (url.pathname === "/api/usage/quotas") { diff --git a/internal/provider/trae_checkin.go b/internal/provider/trae_checkin.go index 1df55e2c4..da5cc20c0 100644 --- a/internal/provider/trae_checkin.go +++ b/internal/provider/trae_checkin.go @@ -16,11 +16,17 @@ package provider // as by account (9095: this device is in for today); that is an answer // for the day, and magpie doesn't send another device id to get round it. // Nor does a claim answered 9074 (当前参与用户太多,请稍后再试) get another -// try that day: Trae pays out only to a device its own app registered -// through its device-register service and security SDK, which the -// plugin's device id isn't, so no retry ever succeeded (#808, ~5 days), -// and claim after claim from an unknown device may read as abuse. The -// account is told to check in in the Trae CN app. +// try that day: no retry ever got past it (#808, ~5 days), and claim +// after claim may read as abuse. Why Trae refuses isn't known for certain. +// It isn't that Trae pays only its own app: Buddy Switch checks in +// accounts that aren't its (#1920). What #808 found is that on one +// account Trae CN's own client's claim went through while the plugin's, +// on a device id the plugin had made up, didn't. So since plugin 0.2.14 +// the account this machine's Trae CN client is signed in as checks in on +// the client's own device id (read, never written); every other account +// keeps its own, and magpie never makes up or rotates one (#1705). An +// account refused 9074 is told that Trae CN refused it, and to check in +// in the Trae CN app. import ( "cmp" @@ -40,6 +46,11 @@ import ( "github.com/yetone/magpie/internal/settings" ) +// TraeRefusedWords is what an account Trae CN refused a claim 9074 is +// told, in the TUI and CLI (the GUI says it in each language): what Trae +// did, and where the check-in can still be done. +const TraeRefusedWords = "Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app" + // TraeCNID is the Trae CN plugin's provider. const TraeCNID = "trae-cn" @@ -49,7 +60,7 @@ var traeCheckinURL = "https://api.trae.cn/trae/api/v2/ug/checkin_credits" // Trae CN's check-in answers, the codes it refuses with. const ( traeSignedOut = 1001 // the token isn't taken - traeOwnAppOnly = 9074 // a claim from a device Trae's app didn't register; final for the day + traeOwnAppOnly = 9074 // a claim refused (当前参与用户太多); final for the day traeDeviceChecked = 9095 // this device is in for today ) @@ -114,9 +125,10 @@ func traeCheckin(ctx context.Context, a traeAccount) WorkBuddyCheckin { return wbCheckinFailed(err) } if got.Code == traeOwnAppOnly { - // status said on and not in, so the claim itself is refused: - // Trae pays only its own app, and asking again won't change it - return WorkBuddyCheckin{Outcome: CheckinOwnApp, Msg: orStr(got.Message, "Trae CN gives check-in credits only to its own app")} + // status said on and not in, so the claim itself is refused, and + // asking again that day never changed it (#808); the account is + // told to check in in Trae CN's app + return WorkBuddyCheckin{Outcome: CheckinOwnApp, Msg: orStr(got.Message, "Trae CN refused the check-in (9074)")} } if got.Code != 0 { return traeRefused(got.Code, got.Message) diff --git a/internal/provider/trae_checkin_test.go b/internal/provider/trae_checkin_test.go index 0c69cbd52..01253cd56 100644 --- a/internal/provider/trae_checkin_test.go +++ b/internal/provider/trae_checkin_test.go @@ -178,9 +178,10 @@ func TestTraeCheckinAnswers(t *testing.T) { } // #808: with the check-in on and today's not in, a claim answered 9074 -// 「当前参与用户太多,请稍后再试」 (the reporter's bytes) is Trae paying -// only its own app: the day's answer, so neither the loop nor a press -// claims again that day; the account is told to check in in Trae's app. +// 「当前参与用户太多,请稍后再试」 (the reporter's bytes) is Trae refusing +// the claim: the day's answer, so neither the loop nor a press claims +// again that day; the account is told Trae CN refused it and to check in +// in Trae's app (#1920). // The next day it is asked as any other. func TestTraeCheckin9074IsOwnAppOnly(t *testing.T) { ctx := context.Background() diff --git a/internal/provider/workbuddy_checkin.go b/internal/provider/workbuddy_checkin.go index 74ed08aa1..b0260d2bb 100644 --- a/internal/provider/workbuddy_checkin.go +++ b/internal/provider/workbuddy_checkin.go @@ -73,9 +73,10 @@ const ( // CheckinCaptcha is a plugin's check-in the vendor asked a captcha // of: the user checks in in its own app, magpie never solves one CheckinCaptcha = "captcha" - // CheckinOwnApp is a check-in the vendor pays out only to its own - // app (Trae CN's 9074 to a device its app didn't register): an - // answer for the day, and the user checks in in the vendor's app + // CheckinOwnApp is a check-in the user is to do in the vendor's own + // app: an answer for the day. WorkBuddy's check-in answered 401 while + // the sign-in works; Trae CN refused the claim with 9074, which says + // so in its own words (#1920), not that only its app is paid CheckinOwnApp = "own-app" ) diff --git a/internal/tui/checkin_test.go b/internal/tui/checkin_test.go index b918ba8bd..c3c912fd5 100644 --- a/internal/tui/checkin_test.go +++ b/internal/tui/checkin_test.go @@ -172,10 +172,11 @@ func TestCheckinOnTheUsageLine(t *testing.T) { {Name: "WorkBuddy", User: "second", Checkins: true, Windows: win, Checkin: &provider.WorkBuddyCheckin{Day: "2020-01-01", Outcome: provider.CheckinClaimed}}, {Name: "WorkBuddy", User: "third", Checkins: true, Error: "sign-in has expired", Checkin: &provider.WorkBuddyCheckin{Day: today, Outcome: provider.CheckinFailed}}, {Name: "WorkBuddy", User: "fourth", Checkins: true, Windows: win, Checkin: &provider.WorkBuddyCheckin{Day: today, Outcome: provider.CheckinOwnApp}}, + {Name: "Trae CN", User: "fifth", Checkins: true, Windows: win, Checkin: &provider.WorkBuddyCheckin{Day: today, By: "trae", Outcome: provider.CheckinOwnApp}}, {Name: "Codex", User: "me@example.com", Windows: win}, } got := strings.Join(quotaLines(qs, true, false, 200, now), "\n") - for _, want := range []string{"签到 ✓ +100 · 4-day streak", "second", "签到 not yet today · c", "sign-in has expired 签到 failed · c tries again", "签到 only in WorkBuddy's own app · check in there"} { + for _, want := range []string{"签到 ✓ +100 · 4-day streak", "second", "签到 not yet today · c", "sign-in has expired 签到 failed · c tries again", "签到 only in WorkBuddy's own app · check in there", "签到 refused by Trae CN (9074) · check in in its app"} { if !strings.Contains(got, want) { t.Errorf("missing %q in\n%s", want, got) } @@ -205,3 +206,17 @@ func TestTUIChecksPluginsIn(t *testing.T) { t.Fatalf("checked in %d times", *calls) } } + +// Trae CN's 9074 says what Trae did, refused the check-in, and where it +// can still be done; it doesn't say Trae pays only its own app, which +// Buddy Switch's check-ins disprove (#1920). WorkBuddy's keeps its words. +func TestTraeOwnAppSaysTraeRefused(t *testing.T) { + trae := checkinWords(provider.WorkBuddyCheckin{User: "hu", By: "trae", Outcome: provider.CheckinOwnApp}) + if !strings.HasSuffix(trae, ": Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app") || strings.Contains(trae, "only gives") { + t.Errorf("Trae CN's 9074: %q", trae) + } + wb := checkinWords(provider.WorkBuddyCheckin{User: "hu", Outcome: provider.CheckinOwnApp}) + if !strings.Contains(wb, "WorkBuddy only gives check-in credits to its own app") { + t.Errorf("WorkBuddy's own-app: %q", wb) + } +} diff --git a/internal/tui/pages.go b/internal/tui/pages.go index 7547d4e3d..e109bf46f 100644 --- a/internal/tui/pages.go +++ b/internal/tui/pages.go @@ -982,9 +982,13 @@ func ownAppName(r provider.WorkBuddyCheckin) string { return "the vendor" } -// ownAppWords says a check-in the vendor pays only to its own app -// (Trae CN's 9074, #808) is to be done in that app. +// ownAppWords says a check-in the vendor pays only to its own app is to +// be done in that app. Trae CN's (9074, #808) says what is known: Trae CN +// refused it; that only its app is paid isn't so (#1920). func ownAppWords(r provider.WorkBuddyCheckin) string { + if r.By == "trae" { + return provider.TraeRefusedWords + } name := ownAppName(r) return name + " only gives check-in credits to its own app; check in in the " + name + " app" } @@ -1017,6 +1021,9 @@ func checkinCell(q provider.SubscriptionQuota, now time.Time) string { case provider.CheckinCaptcha: return sMuted.Render("签到 needs a captcha · check in in its app") case provider.CheckinOwnApp: + if r.By == "trae" { + return sMuted.Render("签到 refused by Trae CN (9074) · check in in its app") + } return sMuted.Render("签到 only in " + ownAppName(*r) + "'s own app · check in there") } return sBad.Render("签到 failed") + sMuted.Render(" · c tries again")