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:
@@ -121,22 +121,23 @@ func (s *session) spawn(ctx context.Context) (*process, error) {
|
||||
// before any user turn so an approval is never silently denied.
|
||||
initCtx, cancel := context.WithTimeout(ctx, initializeTimeout)
|
||||
defer cancel()
|
||||
models, err := p.initialize(initCtx)
|
||||
models, account, err := p.initialize(initCtx)
|
||||
if err != nil {
|
||||
p.close()
|
||||
return nil, err
|
||||
}
|
||||
s.mu.Lock()
|
||||
s.models = models
|
||||
s.account = account
|
||||
s.lastErr = ""
|
||||
s.mu.Unlock()
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *process) initialize(ctx context.Context) ([]protocol.ChatModel, error) {
|
||||
func (p *process) initialize(ctx context.Context) ([]protocol.ChatModel, accountIdentity, error) {
|
||||
raw, err := p.request(ctx, "initialize", map[string]any{"subtype": "initialize"})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("initialize Claude Code: %w%s", err, p.diagnostic())
|
||||
return nil, accountIdentity{}, fmt.Errorf("initialize Claude Code: %w%s", err, p.diagnostic())
|
||||
}
|
||||
var reply struct {
|
||||
Models []struct {
|
||||
@@ -145,9 +146,10 @@ func (p *process) initialize(ctx context.Context) ([]protocol.ChatModel, error)
|
||||
DisplayName string `json:"displayName"`
|
||||
Description string `json:"description"`
|
||||
} `json:"models"`
|
||||
Account json.RawMessage `json:"account"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &reply); err != nil {
|
||||
return nil, errors.New("Claude Code returned an invalid initialize response")
|
||||
return nil, accountIdentity{}, errors.New("Claude Code returned an invalid initialize response")
|
||||
}
|
||||
models := make([]protocol.ChatModel, 0, len(reply.Models))
|
||||
for _, m := range reply.Models {
|
||||
@@ -161,9 +163,9 @@ func (p *process) initialize(ctx context.Context) ([]protocol.ChatModel, error)
|
||||
models = append(models, protocol.ChatModel{ID: m.Value, Provider: Backend, Name: name})
|
||||
}
|
||||
if len(models) == 0 {
|
||||
return nil, errors.New("Claude Code reported no models; check that the CLI is signed in")
|
||||
return nil, accountIdentity{}, errors.New("Claude Code reported no models; check that the CLI is signed in")
|
||||
}
|
||||
return models, nil
|
||||
return models, decodeAccountIdentity(reply.Account), nil
|
||||
}
|
||||
|
||||
// request sends one control request and waits for its control_response.
|
||||
|
||||
Reference in New Issue
Block a user