Commit Graph

8 Commits

Author SHA1 Message Date
William Valentin 478c7529a7 feat(hooks): emit per-run token usage and duration on run.end
The stats layer reads usage/duration only from run.end, but neither
framework populated them, so tokens/cost/avg-duration were always 0.

- hermes: accumulate token usage across each run's api-result calls in
  session state and attach the summed usage plus a computed duration_ms
  (from a stored runStartedAt) onto run.end. metric.snapshot emission is
  unchanged, so there is no double counting.
- claude-code: store runStartedAt and use it as a duration_ms fallback at
  all run.end sites. Usage is unavailable from CC hook inputs.

Live verification: a real hermes run now reports duration_ms and
total_tokens on run.end; dashboard tokens_today/avg_duration_ms, both
previously 0, now populate. cost_today stays 0 (no provider emits cost
through the hooks).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 11:16:23 -07:00
William Valentin 27d40ce28f feat(hooks): add Hermes telemetry handler 2026-05-20 17:35:56 -07:00
William Valentin f8bec2d6d5 fix: ignore non-persistent claude startups 2026-04-30 17:07:19 -07:00
William Valentin fd17628e94 fix: ignore invalid claude hook starts 2026-04-29 09:41:07 -07:00
William Valentin fdfcb50e80 feat(hooks): consolidate shared transport helpers 2026-03-26 11:22:27 -07:00
William Valentin a87bbc6983 fix(claude-hook): derive span durations from start timestamps 2026-03-20 11:17:40 -07:00
William Valentin d235e3c873 feat(hooks): add telemetry handlers for codex/copilot/gemini 2026-03-20 11:17:26 -07:00
William Valentin 2e277fb138 fix: preserve session state across turns in claude-code hook handler
handleNotification("Done") was incorrectly emitting session.end and
calling clearState at the end of each Claude turn. Since "Done" means
a turn finished (not the session), clearing state caused subsequent
tool calls to find no runId, storing spans without run_id and making
them invisible in run-level queries.

- handleNotification: remove session.end emission and clearState call;
  only emit run.end for the completed turn
- handleSessionEnd: load state file to get runId (in-memory activeRuns
  is always empty in a subprocess)
- handlePromptSubmit: load state file to get runId for ending previous
  run before starting a new one

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-18 23:42:22 -07:00