Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 25 additions & 7 deletions bin/omarchy-agent-usage-codex
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def rpc_request(proc, request_id, method, params=None, timeout=8):
raise TimeoutError(method)


def limit_window(window):
def limit_window(window, limit_name=""):
if not isinstance(window, dict):
return None
used = window.get("usedPercent")
Expand All @@ -512,7 +512,7 @@ def limit_window(window):
label = "Limit"
reset = window.get("resetsAt")
return {
"label": label,
"label": f"{limit_name} · {label}" if limit_name else label,
"percent": float(used) / 100.0,
"resetsAt": datetime.fromtimestamp(number(reset), timezone.utc).isoformat() if reset else "",
}
Expand Down Expand Up @@ -548,14 +548,32 @@ def fetch_codex_rpc():
limits_msg = rpc_request(proc, 3, "account/rateLimits/read", timeout=4)

account = (account_msg.get("result") or {}).get("account") or {}
limits = (limits_msg.get("result") or {}).get("rateLimits") or {}
limits_result = limits_msg.get("result") or {}
limits = limits_result.get("rateLimits") or {}
plan = limits.get("planType") or account.get("planType") or account.get("type") or ""
result["tierLabel"] = str(plan) if plan else ""

for window in (limits.get("primary"), limits.get("secondary")):
entry = limit_window(window)
if entry:
result["limits"].append(entry)
limits_by_id = limits_result.get("rateLimitsByLimitId") or {}
if isinstance(limits_by_id, dict) and limits_by_id:
default_limit_id = limits.get("limitId")
ordered_limit_ids = list(limits_by_id)
if default_limit_id in limits_by_id:
ordered_limit_ids.remove(default_limit_id)
ordered_limit_ids.insert(0, default_limit_id)
for limit_id in ordered_limit_ids:
grouped_limits = limits_by_id.get(limit_id)
if not isinstance(grouped_limits, dict):
continue
limit_name = str(grouped_limits.get("limitName") or "")
for window in (grouped_limits.get("primary"), grouped_limits.get("secondary")):
entry = limit_window(window, limit_name)
if entry:
result["limits"].append(entry)
if not result["limits"]:
for window in (limits.get("primary"), limits.get("secondary")):
entry = limit_window(window)
if entry:
result["limits"].append(entry)
except Exception as exc:
result["usageStatusText"] = "Codex limits unavailable"
result["authHelpText"] = str(exc)
Expand Down
28 changes: 23 additions & 5 deletions test/shell.d/agent-usage-codex-scanner-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,28 @@ while read -r request; do
jq -cn --argjson id "$id" '{id: $id, result: {}}'
;;
account/read)
jq -cn --argjson id "$id" '{id: $id, result: {account: {}}}'
jq -cn --argjson id "$id" '{id: $id, result: {account: {planType: "pro"}}}'
;;
account/rateLimits/read)
jq -cn --argjson id "$id" '{id: $id, result: {rateLimits: {}}}'
jq -cn --argjson id "$id" '{id: $id, result: {
rateLimits: {
limitId: "codex",
planType: "pro",
primary: {usedPercent: 94, windowDurationMins: 10080, resetsAt: 1787196799}
},
rateLimitsByLimitId: {
codex: {
limitId: "codex",
limitName: null,
primary: {usedPercent: 94, windowDurationMins: 10080, resetsAt: 1787196799}
},
codex_bengalfox: {
limitId: "codex_bengalfox",
limitName: "GPT-5.3-Codex-Spark",
primary: {usedPercent: 12, windowDurationMins: 10080, resetsAt: 1787357885}
}
}
Comment on lines +43 to +54
}}'
;;
esac
done
Expand All @@ -51,9 +69,9 @@ pass "Codex collector counts each turn once"
fail "Codex collector does not double-count cache or reasoning tokens" "$result"
pass "Codex collector does not double-count cache or reasoning tokens"

[[ $(jq -c '.id + "/" + (.limits|tostring)' <<<"$result") == '"codex/[]"' ]] ||
fail "Codex collector identifies itself with an empty limits list" "$result"
pass "Codex collector identifies itself with an empty limits list"
[[ $(jq -c '{id, tierLabel, limits}' <<<"$result") == '{"id":"codex","tierLabel":"pro","limits":[{"label":"Weekly (7-day)","percent":0.94,"resetsAt":"2026-08-20T03:33:19+00:00"},{"label":"GPT-5.3-Codex-Spark · Weekly (7-day)","percent":0.12,"resetsAt":"2026-08-22T00:18:05+00:00"}]}' ]] ||
fail "Codex collector includes every named usage pool without duplicating the default pool" "$result"
pass "Codex collector includes every named usage pool without duplicating the default pool"

# Pi and omp can both spend a Codex subscription without creating native
# Codex sessions. Their compatible JSONL transcripts must be included.
Expand Down