Repository navigation
feat: add track Kiro CLI usage - #170
Merged
Merged
Conversation
Kiro CLI (a rebrand of aws/amazon-q-developer-cli) keeps its conversation history locally in `~/Library/Application Support/kiro-cli/data.sqlite3`, but no provider read it, so those tokens never reached the companion or the usage tracker. Add `LocalKiroProvider` on top of the shared additional-source cache and register it in `UsageStore.init`. Kiro's `RequestMetadata` (verified against its upstream source) never persists a real token count: - `user_prompt_length` is only the bytes of the message the user just typed (`conversation_state.user_input_message.content.len()` in the upstream Rust), not the full resent prompt. Kiro has no server-side session, so every turn resends the whole conversation — using this field as-is would undercount a long-running conversation by orders of magnitude. - The reader instead accumulates each turn's `user`/`assistant` text byte-by-byte across the conversation (bytes/4 estimate), seeded with `latest_summary` so post-compaction turns still count the history a summary stands in for. - `response_size` (accumulated from the real streamed response/tool-input bytes) has no such gap and is used as-is for output. Two schema generations coexist and are both read: `conversations_v2` (kiro-cli < 2.0.1, dedicated id/timestamp columns) and `conversations` (2.0.1+, keyed by working directory, id embedded in the JSON). Kiro also deletes turns from its database on `/clear` or compaction, unlike every other local source here whose on-disk log only grows. The `.kiro` cache case merges each scan with previously-seen entries instead of replacing them, so a cleared conversation's already-counted tokens stay counted for the rest of the app's process lifetime. Tokens are a byte-based estimate with nothing more precise available locally, so the provider reports tokens only (`reportsCost = false`), same reasoning as Copilot.
Closes the one open item from issue chattymin#115's Definition of Done — a store-level test asserting a new provider's snapshot reaches today/week/month totals and burn tier, mirroring testAggregatesTodayTokensAcrossProviders / testBurnTierCombinesProviders. Parser/schema coverage for Kiro itself already lives in KiroUsageTests.swift.
Owner
|
Thank you for your contribution! |
7 of 10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Kiro CLI stores conversation history locally in
~/Library/Application Support/kiro- cli/data.sqlite3, but no provider previously read it. This PR addsLocalKiroProviderto track Kiro CLI token usage and feed it into companion progression and usage tracking.Key Implementation Details:
LocalKiroProviderRegistration: Implemented on top of the shared additional-source cache and registered inUsageStore.init. Reports tokens only (reportsCost = false), as Kiro does not report per-token dollar costs.conversations_v2(kiro-cli < 2.0.1, dedicated ID/timestamp columns) andconversations(kiro-cli 2.0.1+, directory-keyed withconversation_idinside JSON).- Kiro lacks server-side sessions and resends the entire conversation history on every turn. Because
user_prompt_lengthonly records the immediate user input bytes, the reader accumulatesuserandassistanttext lengths byte-by-byte (using a 4-bytes-per-token heuristic).- Seeded with
latest_summaryso post-compaction turns continue counting the history represented by the summary.- Base64
imagesblobs are excluded from byte counting to prevent token inflation.- Output tokens are estimated directly from actual streamed response bytes (
response_size)./clearor compaction. The.kirocache merges each scan with previously-seen entries so tokens already counted during the app lifecycle are preserved.KiroUsageTests.swift(530 lines) and updated READMEs (EN/KO/JA).Type of change
UI changes
No direct changes under
Sources/PokeTokenBar/UI/.Checklist
swift buildandswift testpass locally