+14








75250d37ac
* Read Codex app-server replies from the raw fd (#13703) * Resolve Codex through mise which instead of running the lazy launcher (#13109) * Skip the Codex app-server probe when there are no credentials (#13106) Adapted: credentials are checked in the home being probed rather than in the CODEX_HOME environment variable, since each registered account is probed in its own home, so a signed-out secondary account isn't hidden behind the primary's login. A home without credentials reports "Waiting for auth" like any other signed-out home. The credentials store setting is read with tomllib, so a single-quoted value counts too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Show the Codex CLI's own error when its app-server dies (#8977) Detect an app-server that exits or stops answering, and report the end of its stderr instead of a bare RPC method name. Rebased onto the raw-fd reply reader; the switch from "-a on-request" to "-a never" is left out, keeping the current approval flags. * Count pi sessions when HOME is a git checkout (#13209) * Count only OpenAI-backed native sessions as Codex usage (#12032) * Deduplicate Pi usage across forked sessions (#8602) * Skip unchanged native Codex token snapshots (#10531) * Count omp and pi profile sessions in the agent usage collectors (#9546) `omp --profile=<name>` (and pi's equivalent) relocates the whole agent tree under <base>/profiles/<name>/. The Claude and Codex collectors only ever scanned <base>/agent/sessions, so a subscription driven entirely through a profile was invisible to the agents panel: no tokens by day, no tokens by model, no prompt or session counts. Discover the profile roots alongside the default one. Sessions are keyed by file path, so a profile adds sessions instead of double-counting the default root, and a missing or unreadable profiles directory leaves the existing behavior untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014zFbJcDEEpV5BAmsH6kAB3 * Skip unrelated Codex session lines before JSON parsing (#12803) Adapted: session_meta lines also pass the pre-filter, since the provider filter from #12032 reads them to skip rollouts served by a non-OpenAI provider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Read only the Codex session files that changed since the last scan (#12595) Native Codex rollouts keep per-file totals between runs, replayed while a file's mtime and size are unchanged. Rebased onto the session_meta provider filter, snapshot dedup, and line pre-filter, which now live in the per-file reader. pi and omp sessions are left out of the per-file cache: a forked pi session repeats its parent's messages, so they are deduplicated across the whole tree on every scan. * Count streamed Claude messages by their highest-output usage line (#10606) Claude Code writes a streamed assistant response as several transcript lines that share one message id, one per content block. Each line carries a usage object. The first line's output_tokens is a placeholder, often 1, and the last line has the real count. Input and cache fields usually match across the lines. The scanner dedupes by message id and keeps the first line it sees, so it under-counts output tokens. On a machine with 2,577 transcripts it reported 39.0M output tokens against 60.1M used, a 35% shortfall. Input and both cache fields differed by under 0.01%. Keep the line with the highest output count, with the last one scanned winning a tie. The whole line is kept because a response can fall back to another model mid-stream. Those lines are separate snapshots with different cache figures and a different model, and taking a maximum per field across them over-counts cache tokens and credits the wrong model. The zero-usage check now runs before dedup, so a zero-usage first line no longer claims a message id and hides a later line with real usage. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: GPT-6 Astra <noreply@openai.com> * Index Claude transcripts so the agents refresh reads only what was appended (#8313) omarchy-agent-usage-claude re-parsed every line of every transcript under ~/.claude/projects on each refresh: no mtime cutoff, no memory of the last pass. The agents widget is on by default and ticks every 15 minutes, so the cost grew for the life of the machine. After one month here that was 803 files, 640 MB, 127k lines and 57k JSON parses per tick, about 1 core-second, pushed through the page cache every quarter hour forever. Keep a per-file index next to the scan cache: the unique usage records already parsed out of each transcript and the byte offset they end at. A file whose size and mtime match is not opened; a file that grew is read from the stored offset; a file that shrank or was rewritten is read from the start. --force drops the index and rescans from scratch. The summary is built from the indexed records in the same directory order the walk always used. That matters: when a resumed session carries earlier messages, the same message id appears in two files with different usage, and the first file visited wins. 91 ids differed on this machine; sorting the walk moved one model's output total by 25k tokens. Output is now byte-identical to the previous scan on a frozen copy of the corpus, cold, warm, and after an append. Warm refresh: 1.0 s -> 0.10 s of CPU, of which the scan itself is 70 ms; the index for this corpus is 2.9 MB. Adapted: - Rebased onto #10606: the highest-output rule for streamed messages now lives where the index parses records, and decides between files too. - The index records the timezone it was written in, and a change rereads every transcript, since its records hold local days. - A file only counts as appended to when its inode and the hash of what was already read still match, so a transcript replaced by a larger one, or rewritten in place, is read from the start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Label a Claude Team seat by its subscription, not its rate-limit tier (#11109) The collector built the plan label from the OAuth rateLimitTier first, so a Team premium seat, which runs on default_claude_max_5x, showed in the agents panel as "Max 5x". Lead with subscriptionType and keep the multiplier as its qualifier: Max still reads "Max 5x", a Team seat reads "Team 5x". Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Label the Claude plan from the profile the CLI refreshes (#7225) Adapted: the profile is found the same way current_account_id() finds it, now shared as profile_path(): ~/.claude.json for the default home, the home's own .claude.json otherwise. The original fell back to ~/.claude.json for any home without CLAUDE_CONFIG_DIR set, so a secondary account read the primary's tier. The profile's tier also keeps the subscription in the label, so a Team seat stays "Team" (#11109). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Call a lapsed Claude access token paused, not signed out (#8093) * Refresh Claude usage after the clock moves backwards (#9956) * Bound unreadable Claude transcript warnings (#12414) * Count Claude usage from opencode v2 sessions (#13894) * Reload agent usage records when an inotify watch fails to rearm (#10067) * Reload agent usage records after each update run instead of on a timer Rather than #10067's two-minute timer per record, reload every record when the omarchy-agent-usage-update process exits, the moment its files can have been replaced. A reload that finds a file unchanged keeps its record, so the panel isn't stirred up by identical data. The grep test now runs the QML functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Show the agent status when the trouble line has no help text (#8497) * Clear stale agent login guidance after a successful probe (#8892) * Clear the Grok login hint after a successful probe #8892 cleared the default login hint after a successful probe in the Claude and Codex collectors; Grok's collector had the same stale hint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Read Fireworks credentials from pi's auth.json (#7455) The Fireworks collector skipped pi, Omarchy's default agent, when walking its credential ladder, so a machine signed in to Fireworks only through pi (/login fireworks) never showed the tab. Insert the key pi stores in $PI_CODING_AGENT_DIR/auth.json (default ~/.pi/agent) between the firectl auth.ini and the opencode fallback. pi keys can be literals, $ENV_VAR/${ENV_VAR} references, or !command shell lookups. The collector resolves the first two; command lookups stay pi-only and are skipped rather than sent to the API verbatim. * Call a lapsed Grok access token paused, not signed out Grok's access token lives six hours and Grok mints a new one from its refresh token whenever it starts, so a lapsed one is routine. Reporting it as an expired sign-in made the panel offer Sign-in required several times a day, sending people through grok login for nothing. With a refresh token present it now reads as paused, like Claude's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep showing Grok's last limits while it sits idle While Grok hasn't run, nothing on the machine has spent its allowance, so with a refresh token on hand the last numbers still stand: they show as current rather than dimmed under a status line. A weekly window that reset in the meantime starts over at 0%, a whole number of weeks on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Ask for a Grok sign-in once its refresh token is past 30 days A refresh token older than Grok's 30-day sign-in can't renew anything, so the panel offers Sign-in required again instead of showing the last limits as current. With nothing cached yet it says to start Grok, rather than showing an empty section without a word. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Check both ends of what the Claude index read before resuming a transcript A transcript rewritten in place could grow and change only after its first kilobytes, and the index took it for an append. It now compares the last kilobytes before the resume point too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Simplify the agent usage collectors - Codex: pass the forced-scan choice down instead of a module global, make the per-file reader's cache arguments required, shrink the cache record check, and drop guards for shapes that can't occur: an empty launcher path, realpath raising, mise itself being a lazy launcher, multi-line `mise which` output, and probing without a temp file for stderr. - Claude: decide an append by the digest of both ends of what was read alone; the inode and mtime checks it made redundant are gone. - Snapshot: the device id falls back to the hostname, which always exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Share fixture setup in the agent usage scanner tests Every fixture home lives under one scratch directory with a single cleanup trap, instead of a trap rewritten with a longer list for each new home, and the Codex test builds its signed-in homes with one helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Treat a replaced Claude transcript as new even when its ends match Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Probe Codex without its error text when there's no temporary space Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: tossbaws <17258053+tossbaws@users.noreply.github.com> Co-authored-by: surim0n <suritech@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: anonwurcod <anonwurcod@proton.me> Co-authored-by: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Co-authored-by: Nate Ashby <nate.ashby11@gmail.com> Co-authored-by: Aris Gysel <aris.gysel@me.com> Co-authored-by: Brams <76213579+Brams-s@users.noreply.github.com> Co-authored-by: This_Is_NPC <gabrielfollone27@gmail.com> Co-authored-by: sanjyay <102979855+sanjyay@users.noreply.github.com> Co-authored-by: PapistProtocol <12738904+PapistProtocol@users.noreply.github.com> Co-authored-by: steez <stevedimakos97@gmail.com> Co-authored-by: GPT-6 Astra <noreply@openai.com> Co-authored-by: Ryan Yogan <ryanyogan@gmail.com> Co-authored-by: Oli Denton <41393837+omdenton@users.noreply.github.com> Co-authored-by: Igor Kramar <i@ikramar.ru> Co-authored-by: Martin Eidensten <martin@meibe.se> Co-authored-by: Romain Perron <rdj.perron@gmail.com> Co-authored-by: Omarchy Contributor <contributor@users.noreply.github.com> Co-authored-by: manuaudio <manu@arimaka.com> Co-authored-by: Tyler South <tsouth2@gmail.com> Co-authored-by: whathek <Hek846@users.noreply.github.com> Co-authored-by: Ty Richards <me@tyrichards.com>
267 lines
13 KiB
Bash
267 lines
13 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
|
|
|
require_command jq
|
|
require_command python3
|
|
|
|
test_tmp=$(mktemp -d)
|
|
trap 'rm -rf "$test_tmp"' EXIT
|
|
|
|
export HOME="$test_tmp/home"
|
|
export XDG_STATE_HOME="$test_tmp/state"
|
|
export XDG_CACHE_HOME="$test_tmp/cache"
|
|
export XDG_DATA_HOME="$test_tmp/data"
|
|
unset CLAUDE_CONFIG_DIR CODEX_HOME
|
|
|
|
accounts="$XDG_STATE_HOME/omarchy/agents/accounts"
|
|
mkdir -p "$HOME/.claude/projects" "$HOME/.codex/sessions" "$accounts/claude/work" "$accounts/claude/old" "$accounts/codex/side"
|
|
|
|
future_ms=$(( ($(date +%s) + 3600) * 1000 ))
|
|
open_at=$(python3 -c 'import datetime as dt; print((dt.datetime.now(dt.timezone.utc) + dt.timedelta(hours=3)).isoformat())')
|
|
|
|
credentials() {
|
|
printf '{"claudeAiOauth":{"accessToken":"%s","expiresAt":%s,"rateLimitTier":"%s","subscriptionType":"max"}}\n' "$1" "$2" "$3"
|
|
}
|
|
credentials token-main "$future_ms" default_claude_max_20x >"$HOME/.claude/.credentials.json"
|
|
credentials token-work "$future_ms" default_claude_max_5x >"$accounts/claude/work/.credentials.json"
|
|
credentials token-old 1000 default_claude_max_5x >"$accounts/claude/old/.credentials.json"
|
|
|
|
# A parked account whose sign-in lapsed still has its last numbers on disk.
|
|
mkdir -p "$XDG_CACHE_HOME/omarchy/agent-usage"
|
|
jq -nc --arg open "$open_at" '{fetchedAtMs: 1, limits: [{label: "Weekly (7-day)", percent: 0.4, resetsAt: $open}]}' \
|
|
>"$XDG_CACHE_HOME/omarchy/agent-usage/claude-limits-old.json"
|
|
|
|
cat >"$accounts/claude.json" <<JSON
|
|
{
|
|
"active": "work",
|
|
"switch": "auto",
|
|
"threshold": 95,
|
|
"accounts": [
|
|
{"id": "main", "label": "Main", "home": "", "primary": true, "email": "me@example.com"},
|
|
{"id": "work", "label": "Work", "home": "$accounts/claude/work", "primary": false, "email": "work@example.com", "accountId": "u-work"},
|
|
{"id": "old", "label": "Old", "home": "$accounts/claude/old", "primary": false, "email": "old@example.com"}
|
|
]
|
|
}
|
|
JSON
|
|
|
|
# Anthropic answers per token, so each account's probe is told apart by the
|
|
# credential it carried.
|
|
claude_record=$(COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" python3 - <<'PY'
|
|
import importlib.machinery, importlib.util, io, json, os, sys
|
|
|
|
loader = importlib.machinery.SourceFileLoader("collector", os.environ["COLLECTOR"])
|
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
|
collector = importlib.util.module_from_spec(spec)
|
|
loader.exec_module(collector)
|
|
|
|
usage = {"token-main": 97.0, "token-work": 12.0}
|
|
|
|
def urlopen(request, timeout=None):
|
|
token = request.get_header("Authorization").split(" ", 1)[1]
|
|
return io.BytesIO(json.dumps({"five_hour": {"utilization": usage[token]}, "seven_day": {"utilization": 5.0}}).encode())
|
|
|
|
collector.urllib.request.urlopen = urlopen
|
|
collector.scan_pi_usage = lambda age: None
|
|
collector.scan_opencode_usage = lambda age: None
|
|
sys.argv = ["omarchy-agent-usage-claude", "--force"]
|
|
collector.main()
|
|
PY
|
|
)
|
|
|
|
[[ $(jq -c '[.accounts[] | {id, active, plan, stale}]' <<<"$claude_record") == '[{"id":"main","active":false,"plan":"Max 20x","stale":false},{"id":"work","active":true,"plan":"Max 5x","stale":false},{"id":"old","active":false,"plan":"Max 5x","stale":true}]' ]] ||
|
|
fail "Claude record lists every account with its own plan" "$claude_record"
|
|
pass "Claude record lists every registered account"
|
|
|
|
[[ $(jq -c '[.accounts[] | .limits[0].percent]' <<<"$claude_record") == '[0.97,0.12,0.4]' ]] ||
|
|
fail "Claude record probes each account with its own sign-in" "$claude_record"
|
|
pass "Claude record probes each account with its own sign-in"
|
|
|
|
[[ $(jq -r '.accounts[2].usageStatusText' <<<"$claude_record") == "Sign-in expired" ]] ||
|
|
fail "a lapsed account keeps its last-known limits and says why" "$claude_record"
|
|
pass "a lapsed account keeps its last-known limits and says why"
|
|
|
|
[[ $(jq -c '{tierLabel, first: .limits[0].percent}' <<<"$claude_record") == '{"tierLabel":"Max 5x","first":0.12}' ]] ||
|
|
fail "the record's own limits describe the active account" "$claude_record"
|
|
pass "the record's own limits describe the active account"
|
|
|
|
[[ -f $XDG_CACHE_HOME/omarchy/agent-usage/claude-limits.json && -f $XDG_CACHE_HOME/omarchy/agent-usage/claude-limits-u-work.json ]] ||
|
|
fail "each account keeps its own limits cache, keyed by subscription"
|
|
pass "each account keeps its own limits cache"
|
|
|
|
# Once every window a lapsed account last saw has reset, it has its whole
|
|
# allowance back: that reads as 0%, not as nothing known.
|
|
past_at=$(python3 -c 'import datetime as dt; print((dt.datetime.now(dt.timezone.utc) - dt.timedelta(minutes=5)).isoformat())')
|
|
jq -nc --arg past "$past_at" '{fetchedAtMs: 1, limits: [{label: "Session (5-hour)", percent: 0.99, resetsAt: $past}]}' \
|
|
>"$XDG_CACHE_HOME/omarchy/agent-usage/claude-limits-old.json"
|
|
rested=$(COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" python3 - <<'PY'
|
|
import importlib.machinery, importlib.util, io, json, os, sys
|
|
|
|
loader = importlib.machinery.SourceFileLoader("collector", os.environ["COLLECTOR"])
|
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
|
collector = importlib.util.module_from_spec(spec)
|
|
loader.exec_module(collector)
|
|
collector.urllib.request.urlopen = lambda request, timeout=None: io.BytesIO(b'{"five_hour": {"utilization": 30.0}}')
|
|
collector.scan_pi_usage = lambda age: None
|
|
collector.scan_opencode_usage = lambda age: None
|
|
sys.argv = ["omarchy-agent-usage-claude", "--force"]
|
|
collector.main()
|
|
PY
|
|
)
|
|
[[ $(jq -c '.accounts[2] | {stale, limits: [.limits[] | {label, empty: (.percent == 0)}]}' <<<"$rested") == '{"stale":true,"limits":[{"label":"Session (5-hour)","empty":true}]}' ]] ||
|
|
fail "a lapsed account whose windows all reset reads as untouched" "$rested"
|
|
pass "a lapsed account whose windows all reset reads as untouched"
|
|
|
|
# A cache stamped ahead of a clock that later stepped back is still what the
|
|
# account last saw, so its reset windows still read as untouched.
|
|
touch -d "@$(( $(date +%s) + 3600 ))" "$XDG_CACHE_HOME/omarchy/agent-usage/claude-limits-old.json"
|
|
rested_future=$(COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" python3 - <<'PY'
|
|
import importlib.machinery, importlib.util, io, json, os, sys
|
|
|
|
loader = importlib.machinery.SourceFileLoader("collector", os.environ["COLLECTOR"])
|
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
|
collector = importlib.util.module_from_spec(spec)
|
|
loader.exec_module(collector)
|
|
collector.urllib.request.urlopen = lambda request, timeout=None: io.BytesIO(b'{"five_hour": {"utilization": 30.0}}')
|
|
collector.scan_pi_usage = lambda age: None
|
|
collector.scan_opencode_usage = lambda age: None
|
|
sys.argv = ["omarchy-agent-usage-claude", "--force"]
|
|
collector.main()
|
|
PY
|
|
)
|
|
[[ $(jq -c '.accounts[2] | {stale, limits: [.limits[] | {label, empty: (.percent == 0)}]}' <<<"$rested_future") == '{"stale":true,"limits":[{"label":"Session (5-hour)","empty":true}]}' ]] ||
|
|
fail "a future-dated cache of reset windows still reads as untouched" "$rested_future"
|
|
pass "a future-dated cache of reset windows still reads as untouched"
|
|
|
|
# Signing the primary home in to another subscription must not inherit the
|
|
# last one's numbers when the first probe for the new one fails.
|
|
printf '{"oauthAccount":{"accountUuid":"u-new"}}\n' >"$HOME/.claude.json"
|
|
now_ms=$(( $(date +%s) * 1000 ))
|
|
jq -nc --arg open "$open_at" --argjson now "$now_ms" '{fetchedAtMs: $now, limits: [{label: "Session (5-hour)", percent: 0.55, resetsAt: $open}]}' \
|
|
>"$XDG_CACHE_HOME/omarchy/agent-usage/claude-limits.json"
|
|
resigned=$(COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" python3 - <<'PY'
|
|
import importlib.machinery, importlib.util, io, json, os, sys
|
|
|
|
loader = importlib.machinery.SourceFileLoader("collector", os.environ["COLLECTOR"])
|
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
|
collector = importlib.util.module_from_spec(spec)
|
|
loader.exec_module(collector)
|
|
|
|
def urlopen(request, timeout=None):
|
|
if request.get_header("Authorization").endswith("token-main"):
|
|
raise collector.urllib.error.URLError("down")
|
|
return io.BytesIO(b'{"five_hour": {"utilization": 12.0}}')
|
|
|
|
collector.urllib.request.urlopen = urlopen
|
|
collector.scan_pi_usage = lambda age: None
|
|
collector.scan_opencode_usage = lambda age: None
|
|
sys.argv = ["omarchy-agent-usage-claude", "--force"]
|
|
collector.main()
|
|
PY
|
|
)
|
|
[[ $(jq -c '.accounts[0].limits | map(.percent)' <<<"$resigned") != *0.55* ]] ||
|
|
fail "a primary home signed in to another subscription doesn't inherit its limits" "$resigned"
|
|
rm -f "$HOME/.claude.json"
|
|
pass "a primary home signed in to another subscription doesn't inherit its limits"
|
|
|
|
# A registry with one account changes nothing about the record.
|
|
jq '.accounts |= [.[0]] | .active = "main"' "$accounts/claude.json" >"$test_tmp/one.json"
|
|
mv "$test_tmp/one.json" "$accounts/claude.json"
|
|
single=$(COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" python3 - <<'PY'
|
|
import importlib.machinery, importlib.util, io, json, os, sys
|
|
|
|
loader = importlib.machinery.SourceFileLoader("collector", os.environ["COLLECTOR"])
|
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
|
collector = importlib.util.module_from_spec(spec)
|
|
loader.exec_module(collector)
|
|
collector.urllib.request.urlopen = lambda request, timeout=None: io.BytesIO(b'{"five_hour": {"utilization": 30.0}}')
|
|
collector.scan_pi_usage = lambda age: None
|
|
collector.scan_opencode_usage = lambda age: None
|
|
sys.argv = ["omarchy-agent-usage-claude", "--force"]
|
|
collector.main()
|
|
PY
|
|
)
|
|
[[ $(jq 'has("accounts")' <<<"$single") == false && $(jq '.limits[0].percent' <<<"$single") == 0.3 ]] ||
|
|
fail "a single account record carries no accounts list" "$single"
|
|
pass "a single account record is unchanged"
|
|
|
|
[[ $(jq -c '{limitsStale, fresh: (.limitsFetchedAt > 0)}' <<<"$single") == '{"limitsStale":false,"fresh":true}' ]] ||
|
|
fail "limits checked just now aren't stale" "$single"
|
|
# A failed probe falls back on hour-old numbers, and the record says so.
|
|
hour_ago_ms=$(( ($(date +%s) - 3600) * 1000 ))
|
|
jq -nc --arg open "$open_at" --argjson at "$hour_ago_ms" '{fetchedAtMs: $at, limits: [{label: "Session (5-hour)", percent: 0.42, resetsAt: $open}]}' \
|
|
>"$XDG_CACHE_HOME/omarchy/agent-usage/claude-limits.json"
|
|
kept=$(COLLECTOR="$ROOT/bin/omarchy-agent-usage-claude" python3 - <<'PY'
|
|
import importlib.machinery, importlib.util, os, sys
|
|
|
|
loader = importlib.machinery.SourceFileLoader("collector", os.environ["COLLECTOR"])
|
|
spec = importlib.util.spec_from_loader(loader.name, loader)
|
|
collector = importlib.util.module_from_spec(spec)
|
|
loader.exec_module(collector)
|
|
|
|
def urlopen(request, timeout=None):
|
|
raise collector.urllib.error.URLError("down")
|
|
|
|
collector.urllib.request.urlopen = urlopen
|
|
collector.scan_pi_usage = lambda age: None
|
|
collector.scan_opencode_usage = lambda age: None
|
|
sys.argv = ["omarchy-agent-usage-claude", "--force"]
|
|
collector.main()
|
|
PY
|
|
)
|
|
[[ $(jq -c --argjson at "$hour_ago_ms" '{limitsStale, at: (.limitsFetchedAt == $at), first: .limits[0].percent}' <<<"$kept") == '{"limitsStale":true,"at":true,"first":0.42}' ]] ||
|
|
fail "kept limits are marked stale with when they were measured" "$kept"
|
|
pass "the record says when its limits are kept from an earlier check"
|
|
|
|
# ------------------------------------------------------------------------ codex
|
|
|
|
# A stand-in app-server that answers for whichever home it was started in.
|
|
mkdir -p "$test_tmp/bin"
|
|
cat >"$test_tmp/bin/codex" <<'PY'
|
|
#!/usr/bin/python3
|
|
import json, os, sys
|
|
used = 91 if os.environ.get("CODEX_HOME", "").endswith("/side") else 40
|
|
for line in sys.stdin:
|
|
message = json.loads(line)
|
|
if "id" not in message:
|
|
continue
|
|
result = {}
|
|
if message["method"] == "account/rateLimits/read":
|
|
result = {"rateLimits": {"planType": "pro", "primary": {"usedPercent": used, "windowDurationMins": 300}}}
|
|
print(json.dumps({"id": message["id"], "result": result}), flush=True)
|
|
PY
|
|
chmod +x "$test_tmp/bin/codex"
|
|
touch "$HOME/.codex/auth.json" "$accounts/codex/side/auth.json"
|
|
|
|
cat >"$accounts/codex.json" <<JSON
|
|
{
|
|
"active": "main",
|
|
"accounts": [
|
|
{"id": "main", "label": "Main", "home": "", "primary": true},
|
|
{"id": "side", "label": "Side", "home": "$accounts/codex/side", "primary": false}
|
|
]
|
|
}
|
|
JSON
|
|
|
|
codex_record=$(PATH="$test_tmp/bin:$PATH" "$ROOT/bin/omarchy-agent-usage-codex" --force)
|
|
[[ $(jq -c '[.accounts[] | {id, active, used: .limits[0].percent}]' <<<"$codex_record") == '[{"id":"main","active":true,"used":0.4},{"id":"side","active":false,"used":0.91}]' ]] ||
|
|
fail "Codex record asks each account's own app-server" "$codex_record"
|
|
[[ $(jq '.limits[0].percent' <<<"$codex_record") == 0.4 ]] || fail "Codex record's own limits describe the active account" "$codex_record"
|
|
pass "Codex record lists every registered account"
|
|
|
|
inherited=$(CODEX_HOME="$accounts/codex/side" PATH="$test_tmp/bin:$PATH" "$ROOT/bin/omarchy-agent-usage-codex" --force)
|
|
[[ $(jq -c '[.accounts[] | .limits[0].percent]' <<<"$inherited") == '[0.4,0.91]' ]] ||
|
|
fail "Main's Codex limits come from ~/.codex whatever CODEX_HOME says" "$inherited"
|
|
pass "Main's Codex limits come from ~/.codex whatever CODEX_HOME says"
|
|
|
|
# A secondary home nobody signed in to is waiting for auth, even while
|
|
# ~/.codex holds a login, and its app-server is never started.
|
|
rm "$accounts/codex/side/auth.json"
|
|
signed_out=$(PATH="$test_tmp/bin:$PATH" "$ROOT/bin/omarchy-agent-usage-codex" --force)
|
|
[[ $(jq -c '[.accounts[] | {id, used: .limits[0].percent, status: .usageStatusText}]' <<<"$signed_out") == '[{"id":"main","used":0.4,"status":""},{"id":"side","used":null,"status":"Waiting for auth"}]' ]] ||
|
|
fail "a signed-out Codex home waits for auth on its own" "$signed_out"
|
|
touch "$accounts/codex/side/auth.json"
|
|
pass "a signed-out Codex home waits for auth on its own"
|