Add usage commands, a vendor-neutral usage format and a knowledge base

This commit is contained in:
Ian Gulliver
2026-10-19 15:08:57 -07:00
parent 912225cbd1
commit 8a395d4d6e
17 changed files with 1010 additions and 403 deletions
+11 -23
View File
@@ -225,36 +225,24 @@ func (m *Manager) readCodexRateLimit() {
}
func (m *Manager) setCodexRateLimit(r codex.RateLimitSnapshot) {
m.mu.Lock()
m.rateLimits[api.Codex] = codexRateLimit(r)
m.mu.Unlock()
m.store.Broadcast(api.Event{Kind: "admin.health", Actor: "byre", Payload: map[string]any{}})
m.setVendorUsage(api.Codex, codexUsage(r))
}
func codexRateLimit(r codex.RateLimitSnapshot) map[string]any {
status := "allowed"
func codexUsage(r codex.RateLimitSnapshot) api.Usage {
u := api.Usage{UpdatedAt: time.Now(), Windows: []api.UsageWindow{}}
if r.RateLimitReachedType != "" {
status = "rejected"
u.Rejected = new(string(r.RateLimitReachedType))
}
windows := map[string]any{}
for name, w := range map[string]*codex.RateLimitWindow{"primary": r.Primary, "secondary": r.Secondary} {
if w == nil {
for _, w := range []struct {
name string
w *codex.RateLimitWindow
}{{"primary", r.Primary}, {"secondary", r.Secondary}} {
if w.w == nil {
continue
}
window := map[string]any{"utilization": float64(w.UsedPercent) / 100}
if w.ResetsAt != 0 {
window["resetsAt"] = w.ResetsAt
}
if w.WindowDurationMins != 0 {
window["windowMins"] = w.WindowDurationMins
}
windows[name] = window
u.Windows = append(u.Windows, percentWindow(w.name, float64(w.w.UsedPercent)/100, w.w.ResetsAt, w.w.WindowDurationMins*60))
}
info := map[string]any{"status": status, "unifiedWindows": windows, "planType": r.PlanType}
if r.RateLimitReachedType != "" {
info["rateLimitType"] = r.RateLimitReachedType
}
return info
return u
}
func (m *Manager) codexTurnCompleted(ctx context.Context, l *live, s *codex.Session, turn codex.Turn) error {