Kiro: forward per-turn token counts + session model for the pricing hedge#276
Conversation
PR Summary by QodoForward Kiro per-turn token counts and session model into _kcap_usage (dormant hedge)
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
Context used 1.
|
415c63f to
9f0459f
Compare
… pricing hedge
KiroUsage now reads input/output_token_count (carried only when > 0) and the
session model_id (rts_model_state.model_info) from {id}.json and injects them
into _kcap_usage, so the server can stamp a canonical $usage once Kiro starts
recording token counts. Kiro persists 0 today (the Amazon-Q CLI discards the
API's TokenUsage — upstream aws/amazon-q-developer-cli#2397), so this stays
dormant until then. Credits/context% behaviour is unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9f0459f to
2d4f6b3
Compare
GetValue<string>() on model_id threw if it was present but not a JSON string, and since the whole method is one best-effort try/catch a bad optional field aborted the anchor map — silently dropping credits/context% enrichment for the whole session. Read it defensively (is JsonValue + TryGetValue<string>). Added a regression test with a non-string model_id. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
KiroUsagenow reads Kiro's per-turninput_token_count/output_token_count(carried only when > 0) and the sessionmodel_id(rts_model_state.model_info) from{id}.json, and injects them into the_kcap_usageobject on the turn's final assistant line.Kiro persists these counts as 0 today — the Amazon-Q CLI discards the streaming API's
TokenUsage(upstream aws/amazon-q-developer-cli#2397). So this is a dormant hedge: nothing changes now, but the server stamps a canonical$usage(and pricing/cost lights up) automatically the moment a future kiro-cli release starts recording tokens — no further code change. Credits/context% behaviour is unchanged.Server side (normalizer
$usagestamping + the credits chip) is in the paired kcap-server PR.Tests:
KiroUsageTestscover token+model capture, injection, and the zero-guard (dormant) case. Full CLI unit suite green (2240/2240); AOT publish clean.Closes #275
Linear: AI-1196
🤖 Generated with Claude Code