vps-health-api/agent/claude-usage
le king fu cf72292967 feat(agent): one-shot backfill of the Claude usage history from local transcripts
agent/claude-usage/backfill-history.js runs by hand from the repo (never
from the cron install, the agent is unchanged). It rebuilds the closed days
with the agent's own aggregate() on past windows and writes { days } to the
--out file, which the server merges with `claude-usage-history.js --import`
(an already archived date wins).

Each 30-day window keeps only its 28 inner days and the next steps back 28
days, so a request straddling a window boundary is deduplicated by the
window that keeps it and counted once. The first window stops at D-2. The
walk is bounded by --max-windows (default 24) rather than guessed from file
mtimes, which say nothing of the oldest line a resumed session holds.

It never reads the credentials file, opens no connection, writes only the
--out file (mode 600, never overwritten) and prints counts only.

Refs #55

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 20:44:45 -04:00
..
aggregate.js test(agent): pin ENOENT as a read error below the root, note the subagent-copy limit 2026-10-07 20:53:27 -04:00
backfill-history.js feat(agent): one-shot backfill of the Claude usage history from local transcripts 2026-10-08 20:44:45 -04:00
limits.js fix(agent): no double count across midnight, no freeze on a read error, bounded limits read 2026-10-07 20:29:29 -04:00
push-claude-usage.js fix(agent): no double count across midnight, no freeze on a read error, bounded limits read 2026-10-07 20:29:29 -04:00
run-claude-usage.sh feat(agent): add the claude-usage agent: plan limits, local cache, push 2026-10-04 15:26:15 -04:00
state.js fix(agent): no double count across midnight, no freeze on a read error, bounded limits read 2026-10-07 20:29:29 -04:00