Chat info: account quota per harness (Claude rate_limit_event, Codex account/rateLimits, OpenCode unsupported)

Usage frames carry optional usage.account {harness, source, plan, as_of,
windows[{id,label,used_percent,resets_at}], unsupported}. Claude Code quota
comes from its rate_limit_event stream lines and the initialize account
(plan), shared across chats on the same account. Codex reads
account/rateLimits/read once per connection (re-read when a chat opens after
5 min) and merges account/rateLimits/updated. OpenCode exposes no quota API
and says so. The app's chat info sheet shows an Account usage section with a
progress bar and reset countdown per window, Material and Cupertino.
This commit is contained in:
2026-11-02 18:57:13 +00:00
parent 8a402c1114
commit 10049b8062
26 changed files with 1469 additions and 19 deletions
+29 -1
View File
@@ -68,6 +68,12 @@ type Chat struct {
usage map[string]usageSnapshot
usageOrder uint64
modes map[string]string
// Account quota (quota.go): merged native snapshot and the read schedule.
quota *quotaState
accountReads bool
accountReading bool
accountReadAt time.Time
}
type pendingForm struct {
@@ -139,6 +145,10 @@ func Open(ctx context.Context) (*Chat, error) {
c.Close()
return nil, fmt.Errorf("initialize Codex app-server: %w", err)
}
c.mu.Lock()
c.accountReads = true
c.mu.Unlock()
c.readAccountRateLimits()
return c, nil
}
@@ -279,6 +289,11 @@ func (c *Chat) respond(id json.RawMessage, result any) {
func (c *Chat) emit(frame protocol.ChatEventFrame) {
c.mu.Lock()
if frame.Kind == protocol.ChatEventUsage && frame.Usage != nil {
usage := *frame.Usage
usage.Account = c.accountLocked()
frame.Usage = &usage
}
if frame.Kind == protocol.ChatEventUsage && !c.retainUsageLocked(frame) {
c.mu.Unlock()
return
@@ -343,12 +358,21 @@ func (c *Chat) subscribe(id string) chan protocol.ChatEventFrame {
}
c.subs[id][ch] = struct{}{}
if snapshot, ok := c.usage[id]; ok {
ch <- snapshot.frame
frame := snapshot.frame
if frame.Usage != nil {
usage := *frame.Usage
usage.Account = c.accountLocked()
frame.Usage = &usage
}
ch <- frame
} else if account := c.accountLocked(); account != nil {
ch <- protocol.ChatEventFrame{SessionID: id, Kind: protocol.ChatEventUsage, Usage: &protocol.ChatUsage{Account: account}}
}
if frame, ok := c.compactions[id]; ok {
ch <- frame
}
c.mu.Unlock()
c.readAccountRateLimits()
return ch
}
@@ -764,6 +788,10 @@ func (c *Chat) handleNotification(msg rpcMessage) {
c.receiveUsage(msg.Params)
return
}
if msg.Method == "account/rateLimits/updated" {
c.receiveRateLimits(msg.Params)
return
}
if msg.Method == "serverRequest/resolved" {
var p struct {
ThreadID string `json:"threadId"`