usage: an Antigravity card's pools draw their curve, say when they run out and what the whole holds

max2020 (Discord #help, 10-27): "为什么反重力这里没有额度的预测和对价格的预估".
An Antigravity card's rows are its pools' windows (Gemini · 5 hours,
Claude & GPT · 7 days …). They are Aside, since routing reads the
models' own windows, and the models' windows are a Family's. So:
- quota history (pointOf) kept none of them. The card had no curve and
  no "Runs out … at this pace" line, though noteQuotaHistory and the
  GUI already name a pool's line "Pool · window" (9ccabdfbd said pools
  are kept; the Aside check left them out from the start).
- holdsBounds left every Family, Pool and Aside window out, so no
  "Whole ≈ N tokens · ≈ $X" and not even "not enough data".

Now a pool's own window (Pool set, no Family: QuotaWindow.PoolWindow)
is kept in the history under LineName ("Gemini · 5 hours") and has its
whole reckoned. It counts the calls to its own models (CountsIn): the
per-model windows given its pool, else, for a pool read with only its
week (a Starter plan, whose models get no pool), the families its name
says and no other pool took (PoolMembers). A model asked for by its
family's id (gemini-3.8-flash) counts toward its levels' windows.
withRecordedWindowStarts finds a pool's line by the same name. The
models' own windows, and a pool with no models known, are still not
told. Dry runs still skip pools: one pool spent says nothing about a
call to another pool's model.

Run (at a312bf3e3 + this change):
- TestQuotaHistoryKeepsAntigravityPools and
  TestWindowHoldsReckonsAntigravityPools (new).
- go test ./internal/provider ./internal/usage ./internal/gui
  ./internal/cli, skipping #3632's and #3854's tests: usage, cli and
  gui ok. provider's first run hit a full disk (ENOSPC in TempDir); its
  26 failed tests were all TempDir/mkdir "no space left", rerun by name
  with room: ok. Every other provider test passed in the first run.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
- Rebased on 28f3c4d7f (8 files of provider/usage changed upstream): both new
  tests, go test ./internal/usage ok, vet darwin/linux nogui/windows ok.
- app.js is unchanged (it already looks the pool lines up), so no GUI run.

Broken by hand:
- pointOf back to skipping every Aside window: the history test is red
  ("histories = []").
- holdsBounds without the pool case: the holds test is red ("no whole
  reckoned").
- Counts in place of CountsIn: the pool counts every call of the
  account (530000 tokens, want 10000).

Not tried:
- a real Antigravity account. The owner's kept card is a Starter plan
  with 0% used on Gemini and 100% on Claude & GPT, so its 7-day pools
  would read "not enough data" until 5% is used.
- A forecast needs 3 readings over an hour of the current cycle.
- Antigravity's level ids (gemini-3.1-pro-high, claude-opus-4-6-thinking,
  gemini-3.8-flash-tiered) have no API price in models.dev. A pool with
  such calls tells tokens with no $ ("some models have no API price").
- Past cycles (HistoricalWindowHolds) still leave pools out, since a kept
  card has no model ids to count by.
This commit is contained in:
yetone
2026-10-27 18:41:27 +08:00
parent add927e604
commit 14e4d80402
6 changed files with 187 additions and 9 deletions
+6 -6
View File
@@ -172,9 +172,12 @@ func newCycle(a, b QuotaPoint) bool {
}
// pointOf is what w, read at at, says, if it is something to draw; a
// reset told in seconds counts from now, when the windows were made.
// reset told in seconds counts from now, when the windows were made. A
// pool's window is drawn though it is aside for routing: it is the row
// the card shows, where its models' own windows are not (max2020 on
// Discord: an Antigravity card had no curve and no "runs out" line).
func pointOf(w QuotaWindow, at, now time.Time) (QuotaPoint, bool) {
if w.Unlimited || w.Aside || w.Family != "" || w.Name == "" || math.IsNaN(w.Used) {
if w.Unlimited || w.Aside && !w.PoolWindow() || w.Family != "" || w.Name == "" || math.IsNaN(w.Used) {
return QuotaPoint{}, false
}
p := QuotaPoint{At: at.UTC().Truncate(time.Second), Left: math.Round(max(0, min(100, 100-w.Used))*100) / 100}
@@ -296,10 +299,7 @@ func noteQuotaHistory(qs []SubscriptionQuota, now time.Time) {
if h[key] == nil {
h[key] = map[string][]QuotaPoint{}
}
name := w.Name
if w.Pool != "" { // Antigravity's pools each have a 5-hour window
name = w.Pool + " · " + w.Name
}
name := w.LineName() // Antigravity's pools each have a 5-hour window
before := h[key][name]
k := len(before)
var last QuotaPoint
+38
View File
@@ -203,3 +203,41 @@ func TestMergeQuotaHistory(t *testing.T) {
t.Error("a broken file merged")
}
}
// max2020 on Discord: an Antigravity card had no curve and no "runs out
// at this pace" line, as its rows are its pools' windows, which are aside
// for routing, and its models' own windows are a family's. Each pool's
// window is kept under its pool's name, as the card's line looks it up;
// the models' windows still aren't, nor another window set aside.
func TestQuotaHistoryKeepsAntigravityPools(t *testing.T) {
testenv.SetHome(t, t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t0 := time.Date(2026, 10, 27, 8, 0, 0, 0, time.UTC)
r5, rw := t0.Add(3*time.Hour), t0.Add(4*24*time.Hour)
card := func(gemini float64) []SubscriptionQuota {
return []SubscriptionQuota{{Provider: "antigravity", Name: "Antigravity", User: "m@x.com", Windows: []QuotaWindow{
{Name: "Gemini 3.8 Flash (Medium)", Model: "gemini-3.8-flash-medium", Family: "Gemini", Pool: "Gemini", Used: gemini, ResetsAt: &r5},
{Name: "Claude Sonnet 4.6 (Thinking)", Model: "claude-sonnet-4-6-thinking", Family: "Claude", Pool: "Claude & GPT", Used: 40, ResetsAt: &r5},
{Name: "5 hours", Pool: "Gemini", Span: 5 * time.Hour, Aside: true, Used: gemini, ResetsAt: &r5},
{Name: "7 days", Pool: "Gemini", Span: 7 * 24 * time.Hour, Aside: true, Used: gemini / 2, ResetsAt: &rw},
{Name: "5 hours", Pool: "Claude & GPT", Span: 5 * time.Hour, Aside: true, Used: 40, ResetsAt: &r5},
{Name: "Extra", Aside: true, Used: 10, ResetsAt: &rw},
}}}
}
noteQuotaHistory(card(10), t0)
noteQuotaHistory(card(30), t0.Add(time.Hour))
hs := QuotaHistories(t0.Add(-time.Hour), "", "")
if len(hs) != 1 || len(hs[0].Lines) != 3 {
t.Fatalf("histories = %+v, want the three pool windows' lines", hs)
}
five := lineOf(t, hs, "m@x.com", "Gemini · 5 hours")
if len(five) != 2 || five[0].Left != 90 || five[1].Left != 70 || five[0].Start == nil || !five[0].Start.Equal(r5.Add(-5*time.Hour)) {
t.Errorf("Gemini · 5 hours = %+v", five)
}
if week := lineOf(t, hs, "m@x.com", "Gemini · 7 days"); len(week) != 2 || week[1].Left != 85 || !week[0].Start.Equal(rw.Add(-7*24*time.Hour)) {
t.Errorf("Gemini · 7 days = %+v", week)
}
if cl := lineOf(t, hs, "m@x.com", "Claude & GPT · 5 hours"); len(cl) != 2 || cl[0].Left != 60 {
t.Errorf("Claude & GPT · 5 hours = %+v", cl)
}
}
+67
View File
@@ -7,6 +7,7 @@ package provider
// the window's bounds.
import (
"slices"
"strings"
"time"
)
@@ -75,3 +76,69 @@ func (w QuotaWindow) Bounds(readAt time.Time) (start, end time.Time, ok bool) {
func (w QuotaWindow) Counts(model string) bool {
return Limit{Model: w.Model, matches: w.matches}.applies(strings.ToLower(model))
}
// PoolWindow is whether w is one of an Antigravity pool's own windows
// ("Gemini" · 5 hours, · 7 days), the allowance its models share, not a
// model's own window drawing on it.
func (w QuotaWindow) PoolWindow() bool { return w.Pool != "" && w.Family == "" }
// LineName is the name w's readings are kept under (quota-history.json)
// and its line drawn by: a pool's window with its pool's name before its
// own ("Gemini · 5 hours"), as every pool has a "5 hours".
func (w QuotaWindow) LineName() string {
if w.Pool != "" {
return w.Pool + " · " + w.Name
}
return w.Name
}
// CountsIn is whether a call to model counts against w, one of ws, the
// windows of its account's card: a pool's window counts its models' calls
// (PoolMembers), by the model's own id or the one its effort word is a
// level of (gemini-3.8-flash is gemini-3.8-flash-medium's); any other as
// Counts says.
func (w QuotaWindow) CountsIn(ws []QuotaWindow, model string) bool {
if !w.PoolWindow() {
return w.Counts(model)
}
m := strings.ToLower(strings.TrimSpace(model))
if m == "" {
return false
}
for _, o := range PoolMembers(ws, w) {
id := strings.ToLower(o.Model)
if id == m || strings.ToLower(EffortFamily(id)) == m || EffortFamily(m) == EffortFamily(id) {
return true
}
}
return false
}
// PoolMembers are the per-model windows among ws whose models draw on
// pool window w's allowance: the ones its pool's name was given to
// (googleAccount.pools), else, when none was (a pool read with only its
// 7 days, as an Antigravity Starter plan's), the ones of a family its
// name says ("Claude & GPT": Claude, GPT-OSS) and no other pool took. A
// pool named for one model ("Gemini 4 Argon") has only the models it was
// given.
func PoolMembers(ws []QuotaWindow, w QuotaWindow) []QuotaWindow {
var given, family []QuotaWindow
words := strings.FieldsFunc(strings.ToLower(w.Pool), func(r rune) bool { return r == ' ' || r == '&' })
for _, o := range ws {
if o.Family == "" || o.Model == "" {
continue
}
if o.Pool == w.Pool {
given = append(given, o)
continue
}
f, _, _ := strings.Cut(strings.ToLower(o.Family), "-")
if o.Pool == "" && !versioned(w.Pool) && f != "" && slices.Contains(words, f) {
family = append(family, o)
}
}
if len(given) > 0 {
return given
}
return family
}
+6 -2
View File
@@ -70,7 +70,11 @@ func holdsBounds(q provider.SubscriptionQuota, w provider.QuotaWindow, at time.T
if q.Error != "" || q.From != "" || q.User == "" || q.Balance != "" {
return time.Time{}, time.Time{}, "-"
}
if w.Unlimited || w.Aside || w.Family != "" || w.Pool != "" || math.IsNaN(w.Used) {
// An Antigravity pool's window is told, by its models' calls (max2020 on
// Discord); the models' own windows drawing on it, and a pool whose
// models aren't known, aren't.
pool := w.PoolWindow() && len(provider.PoolMembers(q.Windows, w)) > 0
if w.Unlimited || w.Aside && !pool || w.Family != "" || w.Pool != "" && !pool || math.IsNaN(w.Used) {
return time.Time{}, time.Time{}, "-"
}
if w.Used < provider.HoldsFloor {
@@ -232,7 +236,7 @@ func windowHolds(qs []provider.SubscriptionQuota, now, first time.Time, priceOf
}
for _, s := range byAccount[acct] {
b := want[s]
if r.Time.Before(b.start) || r.Time.After(b.end) || !qs[s.q].Windows[s.w].Counts(r.Model) {
if r.Time.Before(b.start) || r.Time.After(b.end) || !qs[s.q].Windows[s.w].CountsIn(qs[s.q].Windows, r.Model) {
continue
}
inRun[s] = append(inRun[s], runs...)
+1 -1
View File
@@ -99,7 +99,7 @@ func withRecordedWindowStarts(cards []provider.SubscriptionQuota, hist []provide
continue
}
for _, l := range h.Lines {
if l.Name != w.Name {
if l.Name != w.LineName() {
continue
}
var observed time.Time
+69
View File
@@ -388,3 +388,72 @@ func TestHoldsPriceTheModelItIsTheSameAs(t *testing.T) {
t.Errorf("a model with no Same as was priced: %+v", pr)
}
}
// max2020 on Discord: an Antigravity card told no whole for its windows,
// not even "not enough data", as its rows are its pools' (Gemini · 5
// hours, Claude & GPT · 5 hours, their weeks) and a pool's window was
// never reckoned. A pool's window counts its own models' calls, a model
// asked for by its family's id (gemini-3.8-flash for the medium level's
// window) too; a pool read with only its week, whose models were given no
// pool (a Starter plan), counts the families its name says. The models'
// own windows are still not told.
func TestWindowHoldsReckonsAntigravityPools(t *testing.T) {
holdsHome(t)
now := holdClock(t, time.Date(2026, 10, 27, 12, 0, 0, 0, time.UTC))
at := func(d time.Duration) *time.Time { x := now.Add(d); return &x }
call := func(user string, ago time.Duration, model string, in, out int) Record {
return Record{Time: now.Add(-ago), Agent: "pi", Provider: "antigravity", ProviderAccount: user, Status: 200, Model: model, Input: in, Output: out}
}
for _, r := range []Record{
call("m@x.com", 9*24*time.Hour, "gemini-3.8-flash", 1, 1), // the log's first call
call("m@x.com", time.Hour, "gemini-3.8-flash", 1000, 1000),
call("m@x.com", 2*time.Hour, "claude-sonnet-4-6", 2000, 2000),
call("m@x.com", 3*time.Hour, "some-other-model", 50000, 50000), // no pool of the card's
call("s@x.com", time.Hour, "gpt-oss-120b", 3000, 1000),
call("s@x.com", 2*time.Hour, "gemini-3-flash", 500, 500),
} {
Append(r)
}
five, week := 5*time.Hour, 7*24*time.Hour
qs := []provider.SubscriptionQuota{
{Provider: "antigravity", User: "m@x.com", Windows: []provider.QuotaWindow{
{Name: "Gemini 3.8 Flash (Medium)", Model: "gemini-3.8-flash-medium", Family: "Gemini", Pool: "Gemini", Used: 20, ResetsAt: at(2 * time.Hour)},
{Name: "Claude Sonnet 4.6", Model: "claude-sonnet-4-6", Family: "Claude", Pool: "Claude & GPT", Used: 25, ResetsAt: at(2 * time.Hour)},
{Name: "5 hours", Pool: "Gemini", Span: five, Aside: true, Used: 20, ResetsAt: at(2 * time.Hour)},
{Name: "5 hours", Pool: "Claude & GPT", Span: five, Aside: true, Used: 25, ResetsAt: at(2 * time.Hour)},
}},
{Provider: "antigravity", User: "s@x.com", Windows: []provider.QuotaWindow{
{Name: "GPT-OSS 120B (Medium)", Model: "gpt-oss-120b-medium", Family: "GPT-OSS", Used: 50, ResetsAt: at(3 * 24 * time.Hour)},
{Name: "Gemini 3 Flash", Model: "gemini-3-flash", Family: "Gemini", Used: 10, ResetsAt: at(3 * 24 * time.Hour)},
{Name: "7 days", Pool: "Claude & GPT", Span: week, Aside: true, Used: 50, ResetsAt: at(3 * 24 * time.Hour)},
}},
}
got := WithWindowHolds(qs, now)
sonnet := (2000*3 + 2000*15) / 1e6
for _, x := range []struct {
q, w int
tokens, routed int64
cost float64 // 0: not priced
}{
{0, 2, 2000 * 5, 2000, 0}, // gemini-3.8-flash has no API price here
{0, 3, 4000 * 4, 4000, sonnet * 4},
{1, 2, 4000 * 2, 4000, 0},
} {
w := got[x.q].Windows[x.w]
h := w.Holds
if h == nil {
t.Fatalf("%s · %s of %s: no whole reckoned (why %q)", w.Pool, w.Name, got[x.q].User, w.HoldsWhy)
}
if h.Tokens != x.tokens || h.Routed.Tokens != x.routed {
t.Errorf("%s · %s of %s: %d tokens whole from %d, want %d from %d", w.Pool, w.Name, got[x.q].User, h.Tokens, h.Routed.Tokens, x.tokens, x.routed)
}
if h.Priced != (x.cost > 0) || !near(h.Cost, x.cost) {
t.Errorf("%s · %s of %s: cost %v (priced %v), want %v", w.Pool, w.Name, got[x.q].User, h.Cost, h.Priced, x.cost)
}
}
for _, x := range [][2]int{{0, 0}, {0, 1}, {1, 0}, {1, 1}} {
if w := got[x[0]].Windows[x[1]]; w.Holds != nil || w.HoldsWhy != "" {
t.Errorf("model window %s: reckoned %+v, why %q", w.Name, w.Holds, w.HoldsWhy)
}
}
}