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:55 +00:00
parent 13e536ec1c
commit 752654f049

View file

@ -19,9 +19,7 @@ set -u
STATE_DIR="${HOME}/.claude/pet"
STATE="${STATE_DIR}/state"
HISTORY="${STATE_DIR}/history.log"
AGENTS_DIR="${STATE_DIR}/agents"
TOKENS_FILE="${STATE_DIR}/agent_tokens"
mkdir -p "$STATE_DIR" "$AGENTS_DIR"
mkdir -p "$STATE_DIR"
# Slurp stdin once (hook JSON). Non-blocking; never hang.
INPUT=""
@ -30,29 +28,7 @@ if [ ! -t 0 ]; then INPUT="$(cat 2>/dev/null || true)"; fi
event="${1:-}"
now=$(date +%s)
# ── emoji maps ──────────────────────────────────────────────────────────────
_agent_emoji() {
case "$1" in
*researcher*) echo "🔬" ;;
*architect*) echo "🏗️" ;;
*critic*) echo "🔪" ;;
*security*) echo "🛡️" ;;
*validator*) echo "✅" ;;
*cost*) echo "💰" ;;
*modal*) echo "☁️" ;;
*fal*ai*|*fal_ai*) echo "🎨" ;;
*ml-implementer*|*ml_implementer*) echo "🧠" ;;
*ml-researcher*|*ml_researcher*) echo "📚" ;;
*infra*) echo "🔧" ;;
*implementer*) echo "⚙️" ;;
*patent*) echo "📜" ;;
Explore|*explore*) echo "🔭" ;;
Plan|*plan*) echo "📐" ;;
*general*) echo "🤖" ;;
*) echo "🤖" ;;
esac
}
# ── language emoji map (agent emojis live in the renderer keisei-pet.sh) ─────
_lang_emoji() {
case "$1" in
rs) echo "🦀" ;;
@ -88,34 +64,10 @@ if [ "${day:-}" != "$today" ]; then rust_today=0; patents_today=0; violations=0;
# ── agent / plan / language events (do not change mood face) ─────────────────
case "$event" in
agent_start)
sub="$(printf '%s' "$INPUT" | jq -r '.tool_input.subagent_type // .tool_input.description // "agent"' 2>/dev/null)"
[ -z "$sub" ] && sub="agent"
em="$(_agent_emoji "$sub")"
short="$(printf '%s' "$sub" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9].*$//' | cut -c1-12)"
[ -z "$short" ] && short="agent"
id="${now}-$$-${RANDOM}"
printf '%s|%s|%s\n' "$em" "$short" "$now" > "$AGENTS_DIR/$id" 2>/dev/null || true
printf '%s agent_start %s\n' "$(date -u +%FT%TZ)" "$short" >> "$HISTORY" 2>/dev/null || true
exit 0
;;
agent_done)
# extract tokens from the PostToolUse Agent payload. Claude Code puts the
# sub-agent's usage at .tool_response.totalTokens (camelCase) — verified
# 2026-05-22. Fall back to summing .tool_response.usage if absent.
tok="$(printf '%s' "$INPUT" | jq -r '.tool_response.totalTokens // ((.tool_response.usage.input_tokens // 0) + (.tool_response.usage.output_tokens // 0)) // empty' 2>/dev/null)"
[ "${tok:-0}" = "0" ] && tok=""
if [ -n "${tok:-}" ]; then
prev=0; [ -f "$TOKENS_FILE" ] && prev="$(cat "$TOKENS_FILE" 2>/dev/null || echo 0)"
echo $(( prev + tok )) > "$TOKENS_FILE" 2>/dev/null || true
fi
# remove the oldest running-agent file (FIFO approximation — hooks give no
# stable per-agent id to match start↔done exactly).
oldest="$(ls -1tr "$AGENTS_DIR" 2>/dev/null | head -1)"
[ -n "$oldest" ] && rm -f "$AGENTS_DIR/$oldest" 2>/dev/null || true
printf '%s agent_done tok=%s\n' "$(date -u +%FT%TZ)" "${tok:-none}" >> "$HISTORY" 2>/dev/null || true
exit 0
;;
# NOTE: running-agent tracking + token/cost accounting are NOT done here —
# the kit already does it (hooks/task-timer.sh → time-metrics/.task-*.start,
# hooks/agent-event-done.sh → agent-events.jsonl). keisei-pet.sh READS those
# (SSoT). This updater only owns mood / language / plan / counters.
plan)
plan="📋"; mood="proud"; message="план готов"
;;