mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
Pure aggregation of decrypted NIP-AM turn metrics (kind:44200) into per-agent and fleet token/cost totals — the data core of the agent-owner console. Correctness that makes the numbers trustworthy: turns group by (agent, sessionId); within a session `cumulative` is the monotonic running total, so the max cumulative per field is the authoritative session total (robust to dropped turns), falling back to summing per-turn deltas only where no cumulative exists — per field, so a cumulative that omits costUsd still gets cost from deltas. Delta-sums that include a deltaReliable=false turn flag the fleet estimate. 10 tests cover cumulative-not-summed, missing-turn recovery, delta fallback, per-field mixing, multi-session/multi-agent rollup, sessionless singletons, and the unreliable-estimate flag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8KBSw6smQRyXLiWHeDsZ8