Split agent usage into data files and rename the plugin to omarchy.agents (#6603)
* Add agent usage collectors that write display-ready data files
One omarchy-agent-usage-scan-<agent> collector per AI coding agent prints a
complete display-ready usage record — identity, tier, status, rate limits,
and today/week/all-time stats. omarchy-agent-usage-update runs every
collector it finds and writes the records atomically to
~/.local/state/omarchy/agents/usage/, so anything that displays usage only
ever reads JSON from there.
The Claude collector absorbs what the shell previously did in-process:
transcript scanning, the stats-cache/history fallback, credentials parsing,
and the OAuth limits probe, now with a probe throttle and last-good limits
kept across network failures. The Codex collector is the existing scanner
reshaped to the shared record contract.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Redo the model-usage plugin as omarchy.agents watching usage data files
The panel is now strictly a display. It discovers the JSON records that
omarchy-agent-usage-update maintains under
~/.local/state/omarchy/agents/usage/, watches them for changes, and draws
whatever appears — so adding an agent means shipping a collector, never
touching the panel. Marks resolve by convention (assets/<id>.svg with an
optional -light twin), the limits meters read a generic limits array, and
the per-provider QML adapters and in-plugin scanner scripts are gone.
Cross-device sync aggregation stays in the shell and keeps the snapshot
field names older versions wrote, so mixed-version fleets still merge in
both directions.
With the provider fan-out gone, the widget takes its real name: the plugin
id becomes omarchy.agents. A migration renames it wherever a user's config
mentions it — layout entries keep their settings and position, a disabled
widget stays disabled — then primes the data files once and drops the old
scanner cache. The migration test also drops a stale assertion that expected
migrations to restart the shell themselves, which c992cdff moved to
omarchy update.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Address Codex review: synced-only tabs, limits retry, history fallback
Three data-availability gaps from review. An agent whose records only exist
in synced snapshots — a collector installed on just one machine — now gets
its tab by unioning the synced aggregate into the provider list, with rate
limits blank since those never travel. A Claude limits probe that reaches no
server at all writes retryAdvised into its record, and the shell honors it
with one 30-second retry instead of waiting out the full refresh interval,
restoring the old boot-before-DHCP behavior. And a machine with only
history.jsonl — no transcripts, no stats-cache — still reports today's
prompt and session counts.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Address second Codex pass: history-only visibility, targeted retries
Today's prompt and session counts now count toward an agent's presence in
the bar, so a machine whose only Claude source is history.jsonl shows up
without waiting for limits. And the 30-second limits retry passes the
advising agent ids to the updater, so an outage at one provider no longer
puts every other collector on a retry treadmill.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Drop omarchy-cmd-present jq guards from the agents migrations
jq ships in the default package set, which makes it a runtime invariant per
AGENTS.md — call it directly. The migration tests lose their now-unused
omarchy-cmd-present stubs with it.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Drop the scan infix from the collector command names
Collectors are omarchy-agent-usage-<agent>; the updater skips its own name
when globbing them, and the update test proves it with a decoy.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Keep the credential store out of the printed usage record
The Claude collector now reads .credentials.json once into three scalars —
the access token, its expiry, and the plan label — instead of passing the
parsed store around. The token reaches nothing but the Authorization header
of the limits probe, and only the plan label may travel into the record,
which is what CodeQL's clear-text-logging alert on the record print was
unable to see when the whole dict flowed through.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
c3bd4a86ae
commit
bb8d2f2cb3
+113
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(dirname "$0")/base-test.sh"
|
||||
|
||||
require_command jq
|
||||
|
||||
migration="$ROOT/migrations/1785344985.sh"
|
||||
test_dir=$(mktemp -d)
|
||||
trap 'rm -rf "$test_dir"' EXIT
|
||||
|
||||
mkdir -p "$test_dir/bin"
|
||||
|
||||
cat >"$test_dir/bin/omarchy-restart-shell" <<'STUB'
|
||||
#!/bin/bash
|
||||
|
||||
echo restart >>"$SHELL_RESTARTS"
|
||||
STUB
|
||||
|
||||
chmod +x "$test_dir/bin/"*
|
||||
|
||||
export SHELL_RESTARTS="$test_dir/shell-restarts"
|
||||
|
||||
home="$test_dir/home"
|
||||
config="$home/.config/omarchy/shell.json"
|
||||
|
||||
run_migration() {
|
||||
: >"$SHELL_RESTARTS"
|
||||
HOME="$home" PATH="$test_dir/bin:$PATH" bash -euo pipefail "$migration" >/dev/null
|
||||
}
|
||||
|
||||
# The shipped default minus the widget is what every machine installed before
|
||||
# this migration has on disk.
|
||||
write_config() {
|
||||
rm -rf "$home"
|
||||
mkdir -p "$home/.config/omarchy"
|
||||
jq "${1:-.}" "$ROOT/config/omarchy/shell.json" >"$config"
|
||||
}
|
||||
|
||||
without_widget='del(.bar.layout[][] | select((if type == "object" then .id else . end) == "omarchy.agents"))'
|
||||
|
||||
ids() {
|
||||
jq -c --arg section "$1" '[.bar.layout[$section][]? | if type == "object" then .id else . end]' "$config"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------ shipped default
|
||||
|
||||
jq -e '[.bar.layout.right[].id] | index("omarchy.agents")' "$ROOT/config/omarchy/shell.json" >/dev/null ||
|
||||
fail "shipped config puts the agents widget in the bar"
|
||||
pass "shipped config puts the agents widget in the bar"
|
||||
|
||||
# ------------------------------------------------------------------ placement
|
||||
|
||||
write_config "$without_widget"
|
||||
run_migration
|
||||
|
||||
[[ $(ids right) == '["omarchy.tray","omarchy.agents","omarchy.bluetooth","omarchy.network","omarchy.audio","omarchy.monitor","omarchy.power"]' ]] ||
|
||||
fail "migration inserts the agents widget after the tray" "$(ids right)"
|
||||
pass "migration inserts the agents widget after the tray"
|
||||
|
||||
(($(wc -l <"$SHELL_RESTARTS") == 0)) || fail "migration leaves the shell restart to omarchy update"
|
||||
pass "migration leaves the shell restart to omarchy update"
|
||||
|
||||
before=$(sha256sum "$config")
|
||||
run_migration
|
||||
[[ $before == $(sha256sum "$config") ]] || fail "migration is idempotent" "$(ids right)"
|
||||
pass "migration is idempotent"
|
||||
|
||||
# ------------------------------------------------------------------ curated bars
|
||||
|
||||
# A user who already placed the widget keeps it exactly where they put it, in
|
||||
# whichever section, and never gets a second copy.
|
||||
write_config "$without_widget | .bar.layout.center += [{ id: \"omarchy.agents\" }]"
|
||||
run_migration
|
||||
|
||||
[[ $(ids center) == *'"omarchy.agents"'* ]] || fail "migration leaves a user-placed widget alone" "$(ids center)"
|
||||
[[ $(ids right) != *'"omarchy.agents"'* ]] || fail "migration does not add a second copy" "$(ids right)"
|
||||
pass "migration respects a widget the user already placed"
|
||||
|
||||
# Layouts written before entries grew options are bare id strings.
|
||||
write_config "$without_widget | .bar.layout.right = [\"omarchy.tray\", \"omarchy.agents\", \"omarchy.power\"]"
|
||||
run_migration
|
||||
|
||||
[[ $(ids right) == '["omarchy.tray","omarchy.agents","omarchy.power"]' ]] ||
|
||||
fail "migration reads string-form entries" "$(ids right)"
|
||||
pass "migration reads string-form entries"
|
||||
|
||||
# A tray dropped from the right section must not strand the widget or drop it.
|
||||
write_config "$without_widget | del(.bar.layout.right[] | select(.id == \"omarchy.tray\"))"
|
||||
run_migration
|
||||
|
||||
[[ $(ids right) == '["omarchy.agents",'* ]] || fail "migration places the widget without a tray" "$(ids right)"
|
||||
pass "migration places the widget without a tray"
|
||||
|
||||
# ------------------------------------------------------------------ everything else
|
||||
|
||||
write_config "$without_widget"
|
||||
cp "$config" "$test_dir/before.json"
|
||||
run_migration
|
||||
|
||||
diff <(jq -S 'del(.bar.layout.right)' "$test_dir/before.json") <(jq -S 'del(.bar.layout.right)' "$config") >/dev/null ||
|
||||
fail "migration touches nothing but the right section" "$(diff <(jq -S . "$test_dir/before.json") <(jq -S . "$config"))"
|
||||
pass "migration touches nothing but the right section"
|
||||
|
||||
# A config the migration cannot parse is left alone rather than truncated.
|
||||
rm -rf "$home"
|
||||
mkdir -p "$home/.config/omarchy"
|
||||
printf '{ not json' >"$config"
|
||||
run_migration
|
||||
|
||||
[[ $(cat "$config") == '{ not json' ]] || fail "migration leaves an unparsable config untouched" "$(cat "$config")"
|
||||
pass "migration leaves an unparsable config untouched"
|
||||
Reference in New Issue
Block a user