refactor(pet): read kit agent tracking (SSoT), drop duplicate
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:14:17 +00:00
parent a965ad3b7c
commit 13e536ec1c

View file

@ -1,93 +1,98 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# KeiSei tamagotchi — statusline renderer. Outputs ONE line. # KeiSei tamagotchi — statusline renderer. Outputs ONE line.
# Shows: running sub-agents (emoji·name·elapsed) + agent token spend + # SSoT: reads the kit's OWN tracking, does not maintain a parallel one.
# plan state + mood face + message + counters + current language + project. # - running sub-agents ← ~/.claude/memory/time-metrics/.task-<id>.start
# State written by keisei-pet-update.sh under ~/.claude/pet/. # (written by hooks/task-timer.sh: {id,desc,type,start_epoch})
# - agent token / cost ← ~/.claude/memory/agent-events.jsonl
# (written by hooks/agent-event-done.sh: {tokens,cost_usd,...})
# - mood / lang / plan ← ~/.claude/pet/state (keisei-pet-update.sh)
set -u set -u
# Discard any stdin (Claude Code pipes session JSON to statusLine).
if [ ! -t 0 ]; then cat >/dev/null 2>&1 || true; fi if [ ! -t 0 ]; then cat >/dev/null 2>&1 || true; fi
STATE_DIR="${HOME}/.claude/pet" STATE="${HOME}/.claude/pet/state"
STATE="${STATE_DIR}/state" TM_DIR="${HOME}/.claude/memory/time-metrics"
AGENTS_DIR="${STATE_DIR}/agents" EVENTS="${HOME}/.claude/memory/agent-events.jsonl"
TOKENS_FILE="${STATE_DIR}/agent_tokens"
mood="neutral"; message=""; since=$(date +%s) mood="neutral"; message=""; since=$(date +%s)
rust_today=0; patents_today=0; violations=0; lang=""; plan="" rust_today=0; patents_today=0; violations=0; lang=""; plan=""
# shellcheck source=/dev/null # shellcheck source=/dev/null
[ -f "$STATE" ] && source "$STATE" 2>/dev/null || true [ -f "$STATE" ] && source "$STATE" 2>/dev/null || true
now=$(date +%s) now=$(date +%s)
dim=$'\033[2m'; reset=$'\033[0m' dim=$'\033[2m'; reset=$'\033[0m'
# ── elapsed pretty-printer (s / m / h) ────────────────────────────────────── _agent_emoji() {
case "$1" in
*researcher*) echo "🔬";; *architect*) echo "🏗️";; *critic*) echo "🔪";;
*security*) echo "🛡️";; *validator*) echo "✅";; *cost*) echo "💰";;
*modal*) echo "☁️";; *fal*) echo "🎨";; *ml-implementer*|*ml_implementer*) echo "🧠";;
*ml-researcher*|*ml_researcher*) echo "📚";; *infra*) echo "🔧";; *implementer*) echo "⚙️";;
*patent*) echo "📜";; Explore|*explore*) echo "🔭";; Plan|*plan*) echo "📐";;
*) echo "🤖";;
esac
}
_elapsed() { _elapsed() {
local s=$1 local s=$1
if [ "$s" -lt 60 ]; then printf '%ds' "$s" if [ "$s" -lt 60 ]; then printf '%ds' "$s"
elif [ "$s" -lt 3600 ]; then printf '%dm' $(( s / 60 )) elif [ "$s" -lt 3600 ]; then printf '%dm' $(( s / 60 ))
else printf '%dh%dm' $(( s / 3600 )) $(( (s % 3600) / 60 )) else printf '%dh%dm' $(( s / 3600 )) $(( (s % 3600) / 60 )); fi
fi
} }
# ── running sub-agents (self-clean stale > 1h) ────────────────────────────── # ── running sub-agents (from task-timer's .task-*.start) ─────────────────────
agents="" agents=""; n_agents=0
if [ -d "$AGENTS_DIR" ]; then if [ -d "$TM_DIR" ]; then
for f in "$AGENTS_DIR"/*; do for f in "$TM_DIR"/.task-*.start; do
[ -f "$f" ] || continue [ -f "$f" ] || continue
IFS='|' read -r em name start < "$f" typ="$(jq -r '.type // "agent"' "$f" 2>/dev/null)"
[ -z "${start:-}" ] && { rm -f "$f" 2>/dev/null; continue; } st="$(jq -r '.start_epoch // empty' "$f" 2>/dev/null)"
age=$(( now - start )) [ -z "$st" ] && continue
if [ "$age" -gt 3600 ]; then rm -f "$f" 2>/dev/null; continue; fi age=$(( now - st ))
agents+=" ${em}${name}·$(_elapsed "$age")" [ "$age" -gt 7200 ] && continue # ignore stale (kit removes on done)
short="$(printf '%s' "$typ" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9].*$//' | cut -c1-12)"
agents+=" $(_agent_emoji "$typ")${short}·$(_elapsed "$age")"
n_agents=$((n_agents+1))
done done
fi fi
# ── agent token spend this session ────────────────────────────────────────── # ── agent token / cost spend today (from agent-events.jsonl) ─────────────────
toks="" spend=""
if [ -f "$TOKENS_FILE" ]; then if [ -f "$EVENTS" ]; then
t=$(cat "$TOKENS_FILE" 2>/dev/null || echo 0) today="$(date -u +%Y-%m-%d)"
if [ "${t:-0}" -gt 0 ] 2>/dev/null; then read -r tot_tok tot_cost < <(awk -v d="$today" '
if [ "$t" -ge 1000000 ]; then toks=" 🪙$(( t / 1000000 ))M" index($0,d)>0 {
elif [ "$t" -ge 1000 ] ; then toks=" 🪙$(( t / 1000 ))k" t=0; c=0
else toks=" 🪙${t}" if (match($0,/total_tokens[^0-9]*[0-9]+/)) { s=substr($0,RSTART,RLENGTH); gsub(/[^0-9]/,"",s); t=s }
fi if (match($0,/"cost_usd"[: ]*[0-9.]+/)) { s=substr($0,RSTART,RLENGTH); gsub(/[^0-9.]/,"",s); c=s }
T+=t; C+=c
} END { printf "%d %.4f", T+0, C+0 }' "$EVENTS" 2>/dev/null)
if [ "${tot_cost:-0}" != "0.0000" ] && [ -n "${tot_cost:-}" ]; then
spend=" 💰\$$(printf '%.2f' "$tot_cost" 2>/dev/null)"
elif [ "${tot_tok:-0}" -gt 0 ] 2>/dev/null; then
if [ "$tot_tok" -ge 1000 ]; then spend=" 🪙$(( tot_tok / 1000 ))k"; else spend=" 🪙${tot_tok}"; fi
fi fi
fi fi
# ── mood face + color ─────────────────────────────────────────────────────── # ── mood face ───────────────────────────────────────────────────────────────
idle=$(( now - since )) idle=$(( now - since ))
if [ "$idle" -gt 300 ] && [ "$mood" != "angry" ] && [ "$mood" != "alert" ] && [ -z "${agents// }" ]; then if [ "$idle" -gt 300 ] && [ "$mood" != "angry" ] && [ "$mood" != "alert" ] && [ "$n_agents" -eq 0 ]; then
mood="sleep"; message="zzz" mood="sleep"; message="zzz"
fi fi
case "$mood" in case "$mood" in
happy) face="(ᵔᴥᵔ)"; color=$'\033[32m' ;; happy) face="(ᵔᴥᵔ)"; color=$'\033[32m';; proud) face="(•̀ᴗ•́)و"; color=$'\033[1;32m';;
proud) face="(•̀ᴗ•́)و"; color=$'\033[1;32m';; thinking) face="(⊙.⊙)"; color=$'\033[36m';; alert) face="(ʘᴗʘ)"; color=$'\033[33m';;
thinking) face="(⊙.⊙)"; color=$'\033[36m' ;; angry) face="(ò_ó)"; color=$'\033[31m';; sad) face="(╥﹏╥)"; color=$'\033[34m';;
alert) face="(ʘᴗʘ)"; color=$'\033[33m' ;; sleep) face="(-.-)"; color=$'\033[2;37m';; *) face="(•ᴗ•)"; color=$'\033[37m';;
angry) face="(ò_ó)"; color=$'\033[31m' ;;
sad) face="(╥﹏╥)"; color=$'\033[34m' ;;
sleep) face="(-.-)"; color=$'\033[2;37m';;
*) face="(•ᴗ•)"; color=$'\033[37m' ;;
esac esac
# ── counters ────────────────────────────────────────────────────────────────
stats="" stats=""
[ "${rust_today:-0}" -gt 0 ] 2>/dev/null && stats+=" 🦀${rust_today}" [ "${rust_today:-0}" -gt 0 ] 2>/dev/null && stats+=" 🦀${rust_today}"
[ "${patents_today:-0}" -gt 0 ] 2>/dev/null && stats+=" 📜${patents_today}" [ "${patents_today:-0}" -gt 0 ] 2>/dev/null && stats+=" 📜${patents_today}"
[ "${violations:-0}" -gt 0 ] 2>/dev/null && stats+="${violations}" [ "${violations:-0}" -gt 0 ] 2>/dev/null && stats+="${violations}"
proj="${PWD##*/}"; [ -z "$proj" ] && proj="~" proj="${PWD##*/}"; [ -z "$proj" ] && proj="~"
# ── render ONE line: [agents][tokens] [plan] face msg stats [lang] 📁proj ────
out="" out=""
if [ -n "${agents// }" ]; then if [ -n "${agents// }" ]; then out+="${agents# }${spend} "
out+="${agents# }${toks} " elif [ -n "$spend" ]; then out+="${spend# } "; fi
elif [ -n "$toks" ]; then
out+="${toks# } "
fi
[ -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}"