Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Qoder 国内版、WorkBuddy、Trae 已实现,真账号验收未完成。Kimi C
<img src="./docs/assets/readme/console-window-zh.svg" width="100%" alt="CLI2API 控制台 Accounts 页:每个账号显示登录方式、就绪状态与额度,右侧 Access 面板提供 Base URL 与快速验证">
</p>

就绪状态和额度在账号卡片上。Access 页可以复制 Base URL,并做一次快速验证。哪些供应商能签到由各供应商自己声明,目前是 WorkBuddy、QwenWork、Qoder、Trae、MiniMax Code、码道和 Doubao Work,在卡片上手动签到。自动签到按账号单独开启、默认关闭,时间在「系统 → 自动签到」里按供应商设默认值。真实账号签到验收仍待完成。
就绪状态和额度在账号卡片上。Access 页可以复制 Base URL,并做一次快速验证。哪些供应商能签到由各供应商自己声明,目前是 WorkBuddy 国内版、QwenWork、Qoder、Trae、MiniMax Code、码道和 Doubao Work,在卡片上手动签到。自动签到按账号单独开启、默认关闭,时间在「系统 → 自动签到」里按供应商设默认值。真实账号签到验收仍待完成。

## 最早到期优先

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Qoder CN, WorkBuddy, and Trae are implemented; live-account acceptance is still
<img src="./docs/assets/readme/console-window-en.svg" width="100%" alt="CLI2API console Accounts page: each account shows its login method, ready state, and quota, with an Access panel offering the Base URL and a quick check">
</p>

Readiness and quota sit on the account card. Access copies the Base URL and runs a quick check. Check-in is declared per provider; today that is WorkBuddy, QwenWork, Qoder, Trae, MiniMax Code, CodeArts, and Doubao Work, each with a manual check-in on the card. Automatic check-in is enabled per account and off by default, with the default time per provider under System → Automatic check-in. Live-account check-in acceptance is still pending.
Readiness and quota sit on the account card. Access copies the Base URL and runs a quick check. Check-in is declared per provider; today that is WorkBuddy CN, QwenWork, Qoder, Trae, MiniMax Code, CodeArts, and Doubao Work, each with a manual check-in on the card. Automatic check-in is enabled per account and off by default, with the default time per provider under System → Automatic check-in. Live-account check-in acceptance is still pending.

## Earliest expiry first

Expand Down
19 changes: 19 additions & 0 deletions changelog/unreleased/upstream-checkin-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### English

- Check-in status is now read from the provider instead of trusting the last local attempt. The account API returns upstream `already`, `pending`, `skipped`, or `unknown`, with the last sync time.
- One-click check-in now runs up to four accounts in parallel instead of waiting through the scheduled check-in gap, so a full account set no longer stalls for tens of seconds.
- WorkBuddy queries `/v2/billing/meter/checkin-activity-status` before claiming. Inactive campaigns and same-day repeats are reported as `skipped`/`already` without a duplicate claim. The Global edition no longer advertises or attempts daily check-in because the official desktop disables it.
- Scheduled check-in is automatic by default: the upstream daily window start plus one hour (Qoder 10:00 → 11:00, other providers 00:00 → 01:00). Manual provider times still override auto mode.
- Check-in scheduling uses the provider server clock (`Asia/Shanghai`), not the operator PC's local timezone.
- A campaign status that carries no per-day flag (CodeArts) is treated as provisional until 02:00 Asia/Shanghai; an "already claimed" replay during the first two hours of the day is not recorded as today's success, and the scheduler retries at 02:05, 12:05, and 21:00.
- CodeArts reports `already` only for the `USER_LOGIN` daily campaign, not for a used-up new-user or student reward, and posts the IDE's confirmation step when the claim returns a benefit id.

### 中文

- 签到状态改为读取上游真实状态,不再只信任本地上一次执行结果。账号接口返回上游的已签到、未签到、未开放或状态未知,并标注最近同步时间。
- 一键签到改为最多四个账号并行执行,不再逐个等待定时签到间隔,整批账号不会再卡几十秒。
- WorkBuddy 在领取前先查询 `/v2/billing/meter/checkin-activity-status`。活动未开启和今日已签分别返回 `skipped` / `already`,不会重复领取。由于官方国际版桌面端关闭了签到,国际版不再声明或尝试每日签到。
- 自动签到时间默认改为“上游每日窗口开始 + 1 小时”(Qoder 10:00 → 11:00,其他供应商 00:00 → 01:00)。供应商设置切换为手动时仍按手动时间执行。
- 签到排期按供应商服务器时钟(`Asia/Shanghai`)计算,不再跟随电脑本地时区。
- 不带“当天”字段的活动状态(CodeArts)在服务器时间 02:00 前仍视为待确认;前两小时的“已领取”回放不会被记成今天的成功,调度会在 02:05、12:05、21:00 重试。
- CodeArts 只有 `USER_LOGIN` 每日活动才显示“已签到”,不会再把已用完的新用户/学生奖励当成今天已签;领取返回 benefit id 时补发 IDE 的确认请求。
38 changes: 37 additions & 1 deletion internal/accounts/checkin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,43 @@ func ResolveCheckinTime(ctx context.Context, store CheckinSettingsReader, accoun
if account.CheckinTime != "" {
return NormalizeCheckinTime(account.CheckinTime)
}
return CheckinTimeDefault(ctx, store, account.Provider)
if account.CheckinAutoTime != "" {
return NormalizeCheckinTime(account.CheckinAutoTime)
}
// Before the first upstream status sync, keep the legacy provider default
// as a fallback. The first sync writes CheckinAutoTime and takes over.
fallback, err := CheckinTimeDefault(ctx, store, account.Provider)
if err != nil {
return "", err
}
return fallback, nil
}

// EarliestCheckinClock is the provider's fallback daily window start when the
// upstream status response does not carry one. Qoder's activity refreshes at
// 10:00 Asia/Shanghai; the other currently supported check-in providers roll
// over at local midnight.
func EarliestCheckinClock(provider string) string {
if provider == "qoder" {
return "10:00"
}
return "00:00"
}

// AutoCheckinTimeFromEarliest delays the upstream window by one hour so the
// scheduler never races the reset. An invalid or empty clock returns empty.
func AutoCheckinTimeFromEarliest(earliest string) string {
parsed, err := time.Parse("15:04", strings.TrimSpace(earliest))
if err != nil {
return ""
}
return parsed.Add(time.Hour).Format("15:04")
}

// DefaultCheckinAutoTime is the provider fallback window + 1 hour, used before
// the first upstream sync has produced an account-specific value.
func DefaultCheckinAutoTime(provider string) string {
return AutoCheckinTimeFromEarliest(EarliestCheckinClock(provider))
}

func ValidateCheckinSettings(providerID, regionID string, enabled bool, override string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/accounts/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type AccountStore interface {
ObserveHealth(ctx context.Context, id, remoteUID, lastError, lastKind string) error
SaveQuota(ctx context.Context, id string, quota *QuotaSnapshot) error
RecordCheckin(ctx context.Context, id, status, msg string, at time.Time) error
RecordCheckinStatus(ctx context.Context, id string, update CheckinStatusUpdate) error
ListCheckinRecords(ctx context.Context, accountID string, limit int) ([]CheckinRecord, error)
GetSecret(ctx context.Context, name string) (string, bool, error)
SetSecret(ctx context.Context, name, value string) error
Expand Down
39 changes: 29 additions & 10 deletions internal/accounts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ type Account struct {
CheckinTime string `json:"checkin_time"`
ProxyURL string `json:"-"`
// LastCheckin* are display-only WorkBuddy ops results.
LastCheckinAt string `json:"last_checkin_at,omitempty"`
LastCheckinMsg string `json:"last_checkin_msg,omitempty"`
LastCheckinStatus string `json:"last_checkin_status,omitempty"`
Status string `json:"status"`
LastError string `json:"last_error,omitempty"`
LastErrorKind string `json:"last_error_kind,omitempty"`
CooldownUntil *time.Time `json:"cooldown_until,omitempty"`
Quota *QuotaSnapshot `json:"-"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastCheckinAt string `json:"last_checkin_at,omitempty"`
LastCheckinMsg string `json:"last_checkin_msg,omitempty"`
LastCheckinStatus string `json:"last_checkin_status,omitempty"`
// LastCheckinSource is "local" for a real check-in attempt and "upstream"
// for a status-only read. LastCheckinSyncedAt is when the upstream status
// was last verified, independent of when the check-in happened.
LastCheckinSource string `json:"last_checkin_source,omitempty"`
LastCheckinSyncedAt string `json:"last_checkin_synced_at,omitempty"`
// CheckinAutoTime is the upstream daily window start + 1 hour, stored as
// HH:MM in the provider timezone. Empty means use the provider fallback.
CheckinAutoTime string `json:"checkin_auto_time,omitempty"`
Status string `json:"status"`
LastError string `json:"last_error,omitempty"`
LastErrorKind string `json:"last_error_kind,omitempty"`
CooldownUntil *time.Time `json:"cooldown_until,omitempty"`
Quota *QuotaSnapshot `json:"-"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

type CheckinAllResult struct {
Expand All @@ -76,6 +84,17 @@ type CheckinAllResult struct {
Message string `json:"message,omitempty"`
}

// CheckinStatusUpdate persists an upstream status read. CheckinAt is only set
// when upstream confirms today's check-in; AutoTime is the derived HH:MM slot.
type CheckinStatusUpdate struct {
Status string
Message string
Source string
CheckinAt string
AutoTime string
SyncedAt time.Time
}

type CreateAccount struct {
AutoCheckin *bool
CheckinTime string
Expand Down
3 changes: 3 additions & 0 deletions internal/control/s06_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func (s *fakeStore) SaveQuota(context.Context, string, *accounts.QuotaSnapshot)
func (s *fakeStore) RecordCheckin(context.Context, string, string, string, time.Time) error {
return nil
}
func (s *fakeStore) RecordCheckinStatus(context.Context, string, accounts.CheckinStatusUpdate) error {
return nil
}
func (s *fakeStore) ListCheckinRecords(_ context.Context, accountID string, _ int) ([]accounts.CheckinRecord, error) {
s.log.add("store.ListCheckinRecords")
return s.checkins[accountID], nil
Expand Down
59 changes: 57 additions & 2 deletions internal/providers/checkin.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,80 @@
package providers

import "context"
import (
"context"
"time"
)

// CheckinSureHour is the first hour of the provider's UTC+8 day from which a
// campaign-level status without a per-day flag can be trusted. WorkBuddy
// (today_checked_in), Trae (checked_in), MiniMax (is_today) and QwenWork
// (CLAIMED_TODAY) carry a server-computed day flag and are read directly;
// CodeArts only exposes a campaign status that stays CONFIRMED across days.
// Two hours after the 00:00 rollover leaves room for cache and settlement
// lag before that campaign status is treated as today's.
const CheckinSureHour = 2

// CheckinClaimSettledHour is the first hour from which a claim endpoint's
// "already claimed" answer is trusted. The automatic schedule runs at 01:00
// (earliest window + 1h); a vendor that has not rolled its day yet can still
// answer with yesterday's "already" at that hour. Treat that answer as
// unconfirmed for one more hour and let the retry pick it up, rather than
// recording a false success and skipping the whole day.
const CheckinClaimSettledHour = 2

var checkinCalendarZone = time.FixedZone("UTC+8", 8*3600)

// CheckinCalendarNow returns t in the provider check-in calendar (UTC+8).
func CheckinCalendarNow(t time.Time) time.Time {
return t.In(checkinCalendarZone)
}

// CheckinAnswerProvisional reports whether a campaign-level "already" answer
// at t may still describe the previous provider day. A fresh local success is
// always authoritative and is handled by the runtime separately.
func CheckinAnswerProvisional(t time.Time) bool {
return CheckinCalendarNow(t).Hour() < CheckinSureHour
}

// CheckinClaimProvisional reports whether an "already claimed" answer from the
// claim endpoint is still early enough to be yesterday's stale state.
func CheckinClaimProvisional(t time.Time) bool {
return CheckinCalendarNow(t).Hour() < CheckinClaimSettledHour
}

type CheckinPolicy struct {
// Timezone is the provider's server-side check-in calendar zone, not the
// operator PC's zone. Use an IANA location such as Asia/Shanghai; never
// "Local", so schedules stay stable when the host or browser moves.
Timezone string `json:"timezone"`
}

type CheckinResult struct {
Status string `json:"status"`
Message string `json:"message"`
RewardCredits float64 `json:"reward_credits,omitempty"`
Streak int `json:"streak,omitempty"`
// EarliestCheckin is the upstream daily window start as HH:MM in the
// provider's configured timezone. Empty means the provider did not expose it.
EarliestCheckin string `json:"earliest_checkin,omitempty"`
}

func (result CheckinResult) Valid() bool {
return result.Status == "success" || result.Status == "already" || result.Status == "skipped"
return result.Status == "success" || result.Status == "already" || result.Status == "skipped" ||
result.Status == "pending" || result.Status == "unknown" || result.Status == "error"
}

type AccountCheckiner interface {
Checkin(ctx context.Context, accountID string) (CheckinResult, error)
}

// AccountCheckinStatusReader reads the upstream check-in state without claiming
// anything. Providers that share one endpoint for read and claim only implement
// this when the read path can be separated safely.
type AccountCheckinStatusReader interface {
CheckinStatus(ctx context.Context, accountID string) (CheckinResult, error)
}

func CheckinFor(providerID, regionID string) (*CheckinPolicy, bool) {
_, region, err := Resolve(providerID, regionID)
return region.Checkin, err == nil && region.Checkin != nil
Expand Down
56 changes: 56 additions & 0 deletions internal/providers/checkin_window.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package providers

import (
"strings"
"time"
)

// CheckinClock formats a provider daily window start as HH:MM. Providers that
// return an absolute timestamp use the same +08:00 wall clock their desktop
// clients use for the daily reset, even when the host runs elsewhere.
func CheckinClock(value time.Time) string {
if value.IsZero() {
return ""
}
return value.In(time.FixedZone("UTC+8", 8*3600)).Format("15:04")
}

// CheckinClockFromUnix converts Unix seconds (Qoder campaign windows) to HH:MM.
func CheckinClockFromUnix(seconds int64) string {
if seconds <= 0 {
return ""
}
return CheckinClock(time.Unix(seconds, 0))
}

// CheckinClockFromUnixMillis converts Unix milliseconds (QwenWork nextClaimAt)
// to HH:MM.
func CheckinClockFromUnixMillis(milliseconds int64) string {
if milliseconds <= 0 {
return ""
}
return CheckinClock(time.UnixMilli(milliseconds))
}

// CheckinClockFromText extracts the wall-clock time from the campaign timestamps
// providers return as plain strings ("2026-09-30 00:00:00" or RFC3339).
//
// Timestamps that carry a zone are converted to the provider's UTC+8 calendar;
// timestamps without a zone are already the server's wall clock, so they are
// formatted as-is. This keeps a UTC "00:00Z" from being mistaken for a Beijing
// midnight window.
func CheckinClockFromText(value string) string {
value = strings.TrimSpace(value)
if parsed, err := time.Parse(time.RFC3339Nano, value); err == nil {
return CheckinClock(parsed)
}
for _, layout := range []string{
"2006-01-02 15:04:05",
"2006-01-02 15:04",
} {
if parsed, err := time.Parse(layout, value); err == nil {
return parsed.Format("15:04")
}
}
return ""
}
59 changes: 59 additions & 0 deletions internal/providers/checkin_window_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package providers

import (
"testing"
"time"
)

func mustParse(t *testing.T, value string) time.Time {
t.Helper()
parsed, err := time.Parse(time.RFC3339, value)
if err != nil {
t.Fatal(err)
}
return parsed
}

func TestCheckinClockFromTextUsesProviderCalendar(t *testing.T) {
cases := []struct {
name string
value string
want string
}{
{"naive wall clock", "2026-11-24 00:00:00", "00:00"},
{"utc midnight is beijing morning", "2026-11-23T16:00:00Z", "00:00"},
{"explicit beijing midnight", "2026-11-24T00:00:00+08:00", "00:00"},
{"utc ten is beijing eighteen", "2026-11-24T10:00:00Z", "18:00"},
{"minute precision", "2026-11-24 09:59", "09:59"},
{"empty", "", ""},
{"garbage", "not-a-time", ""},
}
for _, test := range cases {
t.Run(test.name, func(t *testing.T) {
if got := CheckinClockFromText(test.value); got != test.want {
t.Fatalf("CheckinClockFromText(%q)=%q want %q", test.value, got, test.want)
}
})
}
}

func TestCheckinAnswerProvisionalAtDayRollover(t *testing.T) {
if !CheckinAnswerProvisional(mustParse(t, "2026-11-23T17:59:59Z")) { // 01:59 Beijing
t.Fatal("01:59 Beijing must still be provisional")
}
if CheckinAnswerProvisional(mustParse(t, "2026-11-23T18:00:00Z")) { // 02:00 Beijing
t.Fatal("02:00 Beijing must be settled")
}
}

func TestCheckinClaimProvisionalOnlyAroundMidnight(t *testing.T) {
if !CheckinClaimProvisional(mustParse(t, "2026-11-23T16:30:00Z")) { // 00:30 Beijing
t.Fatal("00:30 claim answer must be provisional")
}
if !CheckinClaimProvisional(mustParse(t, "2026-11-23T17:59:59Z")) { // 01:59 Beijing
t.Fatal("01:59 claim answer must be provisional")
}
if CheckinClaimProvisional(mustParse(t, "2026-11-23T18:00:00Z")) { // 02:00 Beijing
t.Fatal("02:00 claim answer must be settled")
}
}
Loading
Loading