feat(pet): show session tokens + context% from statusLine stdin
Some checks are pending
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / preflight (push) Waiting to run
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / vps-smoke (push) Waiting to run
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:frustration-matrix,kei-frustration-loop,kei-skill-importer,kei-projects-index,kei-projects-watcher,kei-gdrive-import,kei-leak-matrix,kei-skills,kei-gateway,kei-cron-scheduler,kei-export-trajectories,kei-backend-daytona,kei-d… (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-compute-baremetal,kei-compute-vultr,kei-compute-linode,kei-compute-digitalocean,kei-svc-systemd,kei-llm-bridge-mlx name:hosted-sleep-compute]) (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-diff,kei-scheduler,kei-watch,kei-prune,kei-discover,kei-brain-view,kei-hibernate,kei-ledger-sign,kei-fork name:wave13-15]) (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-git-gitea,kei-git-forgejo,kei-git-gitlab,kei-git-bitbucket,kei-memory-sled,kei-memory-redis,kei-memory-postgres,kei-memory-sqlite,kei-auth-google,kei-auth-apple,kei-auth-magiclink,kei-auth-webauthn,kei-notify-slack,kei-n… (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-ledger,kei-migrate,kei-changelog,kei-memory,kei-store,kei-conflict-scan,kei-refactor-engine,kei-graph-check,kei-shared,kei-dna-index,kei-pet name:core]) (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-machine-probe,kei-llm-ollama,kei-llm-llamacpp,kei-llm-mlx,kei-llm-router,kei-model name:llm-stack]) (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:kei-router,kei-sage,kei-task,kei-chat-store,kei-crossdomain,kei-search-core,kei-content-store,kei-social-store,kei-curator,kei-auth,kei-artifact name:mcp-lbm]) (push) Blocked by required conditions
CI (Forgejo Actions — self-hosted runner on Mac, host mode) / rust-primitives (map[crates:keisei,kei-forge,kei-runtime,kei-runtime-core,kei-atom-discovery,kei-agent-runtime,kei-capability,kei-provision,kei-entity-store,kei-pipe,kei-cache,kei-spawn,kei-replay name:atom-substrate]) (push) Blocked by required conditions

This commit is contained in:
denis 2026-05-21 17:50:47 +00:00
parent 6d8f07ab90
commit e8df152549

View file

@ -8,7 +8,11 @@
# - mood / lang / plan ← ~/.claude/pet/state (keisei-pet-update.sh) # - mood / lang / plan ← ~/.claude/pet/state (keisei-pet-update.sh)
set -u set -u
if [ ! -t 0 ]; then cat >/dev/null 2>&1 || true; fi # Claude Code pipes the live session JSON to the statusLine on stdin. Capture
# it (don't discard) — it carries this session's token/context/cost, which is
# what replaced the default statusline when the pet took over.
SLINE=""
if [ ! -t 0 ]; then SLINE="$(cat 2>/dev/null || true)"; fi
STATE="${HOME}/.claude/pet/state" STATE="${HOME}/.claude/pet/state"
TM_DIR="${HOME}/.claude/memory/time-metrics" TM_DIR="${HOME}/.claude/memory/time-metrics"
@ -65,10 +69,30 @@ if [ -f "$EVENTS" ]; then
if (match($0,/"cost_usd"[: ]*[0-9.]+/)) { s=substr($0,RSTART,RLENGTH); gsub(/[^0-9.]/,"",s); c=s } if (match($0,/"cost_usd"[: ]*[0-9.]+/)) { s=substr($0,RSTART,RLENGTH); gsub(/[^0-9.]/,"",s); c=s }
T+=t; C+=c T+=t; C+=c
} END { printf "%d %.4f", T+0, C+0 }' "$EVENTS" 2>/dev/null) } END { printf "%d %.4f", T+0, C+0 }' "$EVENTS" 2>/dev/null)
# agent COST only (💰) — session tokens are shown separately as 🪙 above,
# so we don't repeat a token count here. Cost is non-null only when the
# sub-agent payload carried a model.
if [ "${tot_cost:-0}" != "0.0000" ] && [ -n "${tot_cost:-}" ]; then if [ "${tot_cost:-0}" != "0.0000" ] && [ -n "${tot_cost:-}" ]; then
spend=" 💰\$$(printf '%.2f' "$tot_cost" 2>/dev/null)" spend=" 💰\$$(printf '%.2f' "$tot_cost" 2>/dev/null)"
elif [ "${tot_tok:-0}" -gt 0 ] 2>/dev/null; then fi
if [ "$tot_tok" -ge 1000 ]; then spend=" 🪙$(( tot_tok / 1000 ))k"; else spend=" 🪙${tot_tok}"; fi fi
# ── THIS session: tokens + context% (from statusLine stdin) ─────────────────
sess=""
if [ -n "$SLINE" ]; then
read -r s_in s_out s_pct < <(printf '%s' "$SLINE" | jq -r '[
(.context_window.total_input_tokens // 0),
(.context_window.total_output_tokens // 0),
(.context_window.used_percentage // 0)] | @tsv' 2>/dev/null)
st=$(( ${s_in:-0} + ${s_out:-0} ))
if [ "$st" -gt 0 ] 2>/dev/null; then
if [ "$st" -ge 1000000 ]; then tk="$(awk "BEGIN{printf \"%.1fM\",$st/1000000}")"
elif [ "$st" -ge 1000 ]; then tk="$(( st / 1000 ))k"
else tk="$st"; fi
pct="${s_pct%%.*}"; pcol=$'\033[32m'
[ "${pct:-0}" -ge 70 ] 2>/dev/null && pcol=$'\033[33m'
[ "${pct:-0}" -ge 90 ] 2>/dev/null && pcol=$'\033[31m'
sess="🪙${tk} ${pcol}${pct}%${reset}"
fi fi
fi fi
@ -91,8 +115,8 @@ stats=""
proj="${PWD##*/}"; [ -z "$proj" ] && proj="~" proj="${PWD##*/}"; [ -z "$proj" ] && proj="~"
out="" out=""
if [ -n "${agents// }" ]; then out+="${agents# }${spend} " [ -n "$sess" ] && out+="${sess} "
elif [ -n "$spend" ]; then out+="${spend# } "; fi [ -n "${agents// }" ] && out+="${agents# }${spend} "
[ -n "$plan" ] && out+="${plan} " [ -n "$plan" ] && out+="${plan} "
out+="${color}${face}${reset}" out+="${color}${face}${reset}"
[ -n "$message" ] && out+=" ${dim}${message}${reset}" [ -n "$message" ] && out+=" ${dim}${message}${reset}"