feat(events): emit 5-way token breakdown + context-window utilization in message_complete#87
AI Review Completed
The automated AI review has finished successfully.
Details
Review Summary
Review started. Now recording findings.## Review Summary — PR #87: 5-way token breakdown + context-window utilization
Overall: Solid implementation. The buildContextWindow helper is clean, its null/zero handling matches the documented null sentinel contract, the example payload in EVENTS.md is internally consistent (used = 1024 + 8800 + 1024 = 10848, ratio = 0.05424), the non-overlapping bucket definition and context.used = input + cache.read + cache.write are correct, and the ModelNotFoundError-only catch correctly rethrows other errors. No blockers.
Findings (2, both MINOR):
-
Source-text substring tests give false confidence (
usage-token-breakdown.test.ts:149) — Themessage_complete emit block shapedescribe block readsrun.tsas a raw string and asserts substring presence inside arbitrary byte windows. These don't exercise the emit path: they pass if the keywords appear only in comments, break on harmless refactors, and thecontextUsed includes cache.writetest never actually validates the arithmetic. Prefer a behavioral test (stubProvider.getModel, capture theemitpayload) or drop them in favor of the strongbuildContextWindowunit tests. -
reasoningmay emitundefined(silently dropped) (run.ts:497) —JSON.stringifyomitsundefined, so ifStepFinishPartleavesreasoningunset for non-thinking models the field is absent rather than0, breaking the EVENTS.md contract. Verify theinfo.tokensshape; a defensive?? 0on each field guarantees the documented schema.
Both findings recorded via MCP. Review complete.