Reorder the agents in the panel, count Grok's tokens, and install Grok through mise (#14004)
* Let the agents in the panel be put in any order Drag an agent by its mark to move its section; the header it will land on lights up, and the move happens on release. Each agent's header is now a keyboard stop with its own highlight, and Ctrl+Up/Down moves the agent the cursor is in. The order is kept in agents/order.json beside the usage records. The key catcher turns Ctrl+Up/Down into a reorder only for panels that opt in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Light only an agent's mark when the cursor or a drag is on it The mark is the handle the agent moves by, so the keyboard cursor and the drop spot while dragging box it alone rather than the header line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep a lit agent mark's box from being clipped at the panel's edge The box overhangs the content's left edge, which the scrolling area clipped. The scrolling area now reaches a little into the panel's padding with the content shifted back, so nothing moves and the box draws whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Reuse a Grok session scan only on the day it was made A limits-only refresh just after midnight reused a scan from the evening before, which counted yesterday's sessions as today's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep Ctrl+Up/Down from moving an agent when the cursor is outside one The hero's buttons and the starter tiles carry indices too, and the lookup read them as accounts, so with several accounts Ctrl+Up/Down on one of them moved an unrelated agent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Report a failed mise update even after the Grok upkeep runs The Grok block ran after `mise up` and its last command set the script's status, so a failed tool update could read as a success to callers that warn about it. The update's own status is now the script's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Unpack a Grok update into ~/.grok whatever GROK_HOME says The upkeep replaces ~/.grok's link, but the npm launcher unpacks into GROK_HOME when it's set, so with a custom home the link never came back at the new release and the old one was restored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Hold off reordering agents while an account name is being edited Ctrl+Up/Down reached the key catcher during an inline rename, and moving the agent rebuilt its section, dropping the unfinished name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Install Grok through mise's first-party package The npm launcher keeps an old ~/.grok/bin binary because mise skips its postinstall. Use mise's grok tool, and drop the npm tool so its shim does not stay ahead of the stub. * Drop the npm Grok workarounds now that mise installs Grok itself With Grok installed through mise's first-party package, the CLI is the binary mise manages, so the update upkeep that repointed ~/.grok/bin and the shared bin directory for added Grok accounts have nothing left to do. omarchy-update-mise is back to running mise up and nothing else, and adding a first Grok account installs the same package. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Count Grok's tokens and prompts from its usage ledger Each Grok session keeps a usage.json, the ledger `grok usage` prints, with every finished turn's end time and tokens by model. The collector now reads it for tokens today, by day for the last week, and by model, with cached input kept apart, and counts today's prompts by the turns that ended today. Found in #12352's research. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Count cache writes in Grok's daily token totals Grok's totalTokens leaves cache writes out while the per-model buckets count them, so a turn with cache writes added less to its day than to its model. The day's total is now the sum of those same buckets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Remove the npm launcher's old Grok binaries when moving to mise's Grok Omarchy's npm wrapper ran the binary the launcher unpacked into ~/.grok/bin, where x.ai's installer also puts a copy with a PATH entry ahead of mise. Once the wrapper is replaced, a binary left there would keep shadowing the mise tool, so the migration removes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jesse Miller <jmiller@jmiller.com>
This commit is contained in:
17 files changed
+446
-120
No files matched your search
@@ -56,7 +56,7 @@ fi
|
||||
case "${1:-}" in
|
||||
claude) provider="claude"; name="Claude"; site="claude.ai"; package="claude"; home_env="CLAUDE_CONFIG_DIR" ;;
|
||||
codex) provider="codex"; name="Codex"; site="chatgpt.com"; package="codex"; home_env="CODEX_HOME" ;;
|
||||
grok) provider="grok"; name="Grok"; site="x.ai"; package="npm:@xai-official/grok"; home_env="GROK_HOME" ;;
|
||||
grok) provider="grok"; name="Grok"; site="x.ai"; package="grok"; home_env="GROK_HOME" ;;
|
||||
*)
|
||||
echo "Usage: omarchy-agent-account-add [--check] [--events] [--reauth <account>] [claude|codex|grok] [label]" >&2
|
||||
exit 1
|
||||
|
||||
@@ -55,9 +55,7 @@ PROVIDERS = {
|
||||
"grok": {
|
||||
"name": "Grok",
|
||||
"home_env": "GROK_HOME",
|
||||
# bin holds the unpacked CLI itself: sharing it spares every added account
|
||||
# its own 160MB copy, which the npm launcher unpacks into an empty home.
|
||||
"shared_dirs": ["bin", "sessions", "skills", "agents", "plugins", "installed-plugins", "marketplace-cache", "hooks", "memory", "memory-v2", "rules", "commands", "workflows", "personas", "worktrees"],
|
||||
"shared_dirs": ["sessions", "skills", "agents", "plugins", "installed-plugins", "marketplace-cache", "hooks", "memory", "memory-v2", "rules", "commands", "workflows", "personas", "worktrees"],
|
||||
"shared_files": ["config.toml", "settings.json", "lsp.json", "pager.toml", "sandbox.toml", "trusted_folders.toml", "statusline.sh", "worktrees.db"],
|
||||
"carried_keys": [],
|
||||
},
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
The plan comes from the settings Grok caches from xAI, and the limit from the
|
||||
credits endpoint the Grok CLI itself reads for its /usage view, asked with
|
||||
each account's own sign-in. Sessions and prompts come from the summary Grok
|
||||
keeps beside each session; it records no token counts there, nor when each
|
||||
prompt was sent, so neither tokens nor today's prompts are claimed. The
|
||||
agents panel only ever reads the JSON this prints.
|
||||
each account's own sign-in. Sessions come from the summary Grok keeps beside
|
||||
each session, and tokens and prompts from its usage.json, the ledger `grok
|
||||
usage` prints: one entry per finished turn, with when it ended and its tokens
|
||||
by model. The agents panel only ever reads the JSON this prints.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -20,7 +20,7 @@ import tempfile
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
AGENT_ID = "grok"
|
||||
@@ -74,44 +74,88 @@ def default_home():
|
||||
return Path(os.environ.get("GROK_HOME") or (Path.home() / ".grok"))
|
||||
|
||||
|
||||
# Every session's summary, under <home>/sessions/<folder>/<session>/. Added
|
||||
# accounts link their sessions to the primary's, so this covers all of them.
|
||||
# A resumed session's prompts can't be told apart by day, so today counts
|
||||
# sessions only.
|
||||
# Every session under <home>/sessions/<folder>/<session>/: its summary says
|
||||
# when it was last active and how many prompts it had, and its usage.json
|
||||
# lists each finished turn with its tokens by model. Added accounts link
|
||||
# their sessions to the primary's, so this covers all of them. Grok counts
|
||||
# cached input inside inputTokens; the record keeps the two apart, as the
|
||||
# other collectors do.
|
||||
def local_stats(home):
|
||||
today = datetime.now().astimezone().date().isoformat()
|
||||
prompts = sessions = today_sessions = 0
|
||||
now = datetime.now().astimezone()
|
||||
today = now.date().isoformat()
|
||||
week = [(now.date() - timedelta(days=offset)).isoformat() for offset in range(6, -1, -1)]
|
||||
prompts = sessions = today_sessions = today_prompts = today_tokens = 0
|
||||
days = set()
|
||||
for summary_path in (Path(home) / "sessions").glob("*/*/summary.json"):
|
||||
summary = read_json(summary_path)
|
||||
if not isinstance(summary, dict):
|
||||
continue
|
||||
active = parse_time(summary.get("last_active_at"))
|
||||
if not active:
|
||||
continue
|
||||
day = active.astimezone().date().isoformat()
|
||||
sessions += 1
|
||||
prompts += int(summary.get("num_messages") or 0)
|
||||
days.add(day)
|
||||
if day == today:
|
||||
today_sessions += 1
|
||||
by_day = {day: 0 for day in week}
|
||||
today_by_model = {}
|
||||
models = {}
|
||||
for session in (Path(home) / "sessions").glob("*/*/"):
|
||||
summary = read_json(session / "summary.json")
|
||||
if isinstance(summary, dict):
|
||||
active = parse_time(summary.get("last_active_at"))
|
||||
if active:
|
||||
day = active.astimezone().date().isoformat()
|
||||
sessions += 1
|
||||
prompts += int(summary.get("num_messages") or 0)
|
||||
days.add(day)
|
||||
if day == today:
|
||||
today_sessions += 1
|
||||
|
||||
usage = read_json(session / "usage.json")
|
||||
turns = usage.get("turns") if isinstance(usage, dict) else None
|
||||
for turn in turns if isinstance(turns, list) else []:
|
||||
ended = parse_time(turn.get("endedAt")) if isinstance(turn, dict) else None
|
||||
if not ended:
|
||||
continue
|
||||
day = ended.astimezone().date().isoformat()
|
||||
days.add(day)
|
||||
if day == today:
|
||||
today_prompts += 1
|
||||
for model, bucket in (turn.get("modelUsage") or {}).items():
|
||||
if not isinstance(bucket, dict):
|
||||
continue
|
||||
# Grok's totalTokens leaves cache writes out; counting them here keeps
|
||||
# the day's total equal to the sum of its model's buckets.
|
||||
cached = int(bucket.get("cachedReadTokens") or 0)
|
||||
uncached = max(0, int(bucket.get("inputTokens") or 0) - cached)
|
||||
output = int(bucket.get("outputTokens") or 0)
|
||||
created = int(bucket.get("cacheCreationTokens") or 0)
|
||||
tokens = uncached + cached + output + created
|
||||
totals = models.setdefault(model, {"inputTokens": 0, "outputTokens": 0, "cacheReadInputTokens": 0, "cacheCreationInputTokens": 0})
|
||||
totals["inputTokens"] += uncached
|
||||
totals["outputTokens"] += output
|
||||
totals["cacheReadInputTokens"] += cached
|
||||
totals["cacheCreationInputTokens"] += created
|
||||
if day in by_day:
|
||||
by_day[day] += tokens
|
||||
if day == today:
|
||||
today_tokens += tokens
|
||||
today_by_model[model] = today_by_model.get(model, 0) + tokens
|
||||
|
||||
return {
|
||||
"hasLocalStats": sessions > 0,
|
||||
"todayPrompts": today_prompts,
|
||||
"todaySessions": today_sessions,
|
||||
"todayTotalTokens": today_tokens,
|
||||
"todayTokensByModel": today_by_model,
|
||||
"recentDays": [{"date": day, "messageCount": by_day[day]} for day in week],
|
||||
"totalPrompts": prompts,
|
||||
"totalSessions": sessions,
|
||||
"activeDays": len(days),
|
||||
"activeDates": sorted(days),
|
||||
"modelUsage": models,
|
||||
}
|
||||
|
||||
|
||||
# A scan from before midnight would count yesterday's sessions as today's.
|
||||
def cached_local_stats(home, max_age):
|
||||
cache = cache_root() / "grok-stats.json"
|
||||
cached = read_json(cache) or {}
|
||||
if cached.get("home") == str(home) and time.time() - float(cached.get("at") or 0) < max_age:
|
||||
today = datetime.now().astimezone().date().isoformat()
|
||||
if cached.get("home") == str(home) and cached.get("day") == today and time.time() - float(cached.get("at") or 0) < max_age:
|
||||
return cached["stats"]
|
||||
stats = local_stats(home)
|
||||
write_json(cache, {"home": str(home), "at": time.time(), "stats": stats})
|
||||
write_json(cache, {"home": str(home), "day": today, "at": time.time(), "stats": stats})
|
||||
return stats
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ ori | openrouter) agent="ori"; name="Ori"; agent_package="github:OpenRouterLabs/
|
||||
claude | claude-code) agent="claude"; name="Claude Code" ;;
|
||||
codex) agent="codex"; name="Codex" ;;
|
||||
crush) agent="crush"; name="Crush" ;;
|
||||
grok) agent="grok"; name="Grok"; agent_package="npm:@xai-official/grok" ;;
|
||||
grok) agent="grok"; name="Grok" ;;
|
||||
openclaw) agent="openclaw"; name="OpenClaw"; agent_installer="omarchy-install-openclaw-cli" ;;
|
||||
agy | antigravity | antigravity-cli | gemini | gemini-cli) agent="agy"; name="Antigravity"; agent_package="antigravity-cli" ;;
|
||||
hermes) agent="hermes"; name="Hermes"; agent_installer="omarchy-install-hermes-cli" ;;
|
||||
|
||||
@@ -9,25 +9,4 @@ if omarchy-cmd-present mise; then
|
||||
# days after they ship. Running omarchy update is the user asking for current
|
||||
# versions now, which is the same call the mup alias makes by hand.
|
||||
MISE_MINIMUM_RELEASE_AGE=0 mise up
|
||||
|
||||
# Grok's npm launcher runs ~/.grok/bin/grok whenever it exists, and the
|
||||
# package's install script that points it at a new release doesn't run
|
||||
# under mise, so updates never took effect. Dropping a link to an older
|
||||
# release lets the launcher unpack the installed one, which --version does
|
||||
# now rather than on the next session. The old release stays until the new
|
||||
# one is in place, and comes back if it never arrives.
|
||||
if grok_dir=$(mise where npm:@xai-official/grok 2>/dev/null) && [[ -n $grok_dir ]]; then
|
||||
grok_link="$HOME/.grok/bin/grok"
|
||||
grok_current="grok-${grok_dir##*/}"
|
||||
grok_previous=$(readlink "$grok_link" 2>/dev/null)
|
||||
if [[ -L $grok_link && $grok_previous != "$grok_current" ]]; then
|
||||
rm -f "$grok_link"
|
||||
mise x npm:@xai-official/grok -- grok --version >/dev/null 2>&1
|
||||
if [[ $(readlink "$grok_link" 2>/dev/null) == "$grok_current" ]]; then
|
||||
find "$HOME/.grok/bin" -maxdepth 1 -name 'grok-*' ! -name "$grok_current" -delete
|
||||
else
|
||||
ln -sfn "$grok_previous" "$grok_link"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
Reference in new issue
Block a user