-
Notifications
You must be signed in to change notification settings - Fork 153
feat: Add Kiro plugin for usage tracking #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| # Kiro | ||
|
|
||
| > Reverse-engineered from the shipped Kiro extension, local Kiro state, and local Kiro logs. The live API is not publicly documented and may change without notice. | ||
|
|
||
| ## Overview | ||
|
|
||
| - **Product:** [Kiro](https://kiro.dev/) | ||
| - **Runtime service:** AWS CodeWhisperer Runtime (`https://q.<region>.amazonaws.com`) | ||
| - **Primary local state:** `~/Library/Application Support/Kiro/User/globalStorage/state.vscdb` | ||
| - **Primary local metadata fallback:** `~/Library/Application Support/Kiro/logs/*/window*/exthost/kiro.kiroAgent/q-client.log` | ||
| - **Auth token file:** `~/.aws/sso/cache/kiro-auth-token.json` | ||
| - **Profile fallback:** `~/Library/Application Support/Kiro/User/globalStorage/kiro.kiroagent/profile.json` | ||
|
|
||
| OpenUsage uses Kiro's local normalized usage cache first, enriches it from Kiro's own runtime logs when available, and only falls back to the live refresh/API path when the local picture is missing or stale. | ||
|
|
||
| ## Plugin Metrics | ||
|
|
||
| | Metric | Source | Scope | Format | Notes | | ||
| | --- | --- | --- | --- | --- | | ||
| | Credits | `usageBreakdowns[*]` | overview | count | Monthly included Kiro plan credits | | ||
| | Bonus Credits | `freeTrialUsage` or active `bonuses[0]` | overview | count | Free-trial / bonus credit pool when present | | ||
| | Overages | `overageConfiguration.overageStatus` | detail | badge | `Enabled` / `Disabled` | | ||
|
Comment on lines
+18
to
+22
|
||
|
|
||
| The plan label comes from `subscriptionInfo.subscriptionTitle` when a recent `GetUsageLimits` response is available from logs or the live API. | ||
|
|
||
| ## Local Sources | ||
|
|
||
| ### 1) SQLite usage cache | ||
|
|
||
| Path: `~/Library/Application Support/Kiro/User/globalStorage/state.vscdb` | ||
|
|
||
| Key: | ||
|
|
||
| - `kiro.kiroAgent` | ||
|
|
||
| That JSON currently contains a nested key: | ||
|
|
||
| - `kiro.resourceNotifications.usageState` | ||
|
|
||
| Observed shape: | ||
|
|
||
| ```json | ||
| { | ||
| "usageBreakdowns": [ | ||
| { | ||
| "type": "CREDIT", | ||
| "currentUsage": 0, | ||
| "usageLimit": 50, | ||
| "resetDate": "2026-05-01T00:00:00.000Z", | ||
| "displayName": "Credit", | ||
| "displayNamePlural": "Credits", | ||
| "freeTrialUsage": { | ||
| "currentUsage": 106.11, | ||
| "usageLimit": 500, | ||
| "expiryDate": "2026-05-03T15:09:55.196Z", | ||
| "daysRemaining": 27 | ||
| } | ||
| } | ||
| ], | ||
| "timestamp": 1775500185544 | ||
| } | ||
| ``` | ||
|
|
||
| This is the cleanest local source for the numeric usage lines. | ||
|
|
||
| ### 2) q-client runtime logs | ||
|
|
||
| Path pattern: | ||
|
|
||
| ```text | ||
| ~/Library/Application Support/Kiro/logs/<session>/window*/exthost/kiro.kiroAgent/q-client.log | ||
| ``` | ||
|
|
||
| Kiro logs the full `GetUsageLimitsCommand` request/response. That response includes the fields missing from the SQLite cache, especially: | ||
|
|
||
| - `subscriptionInfo.subscriptionTitle` | ||
| - `subscriptionInfo.type` | ||
| - `overageConfiguration.overageStatus` | ||
| - full `usageBreakdownList` | ||
|
|
||
| OpenUsage uses the latest logged response to recover plan metadata without needing network access. | ||
|
|
||
| ## Authentication | ||
|
|
||
| ### Token file | ||
|
|
||
| Kiro's desktop extension stores auth in: | ||
|
|
||
| ```text | ||
| ~/.aws/sso/cache/kiro-auth-token.json | ||
| ``` | ||
|
|
||
| Observed fields: | ||
|
|
||
| ```json | ||
| { | ||
| "accessToken": "...", | ||
| "refreshToken": "...", | ||
| "expiresAt": "2026-04-06T19:29:16.090Z", | ||
| "authMethod": "social", | ||
| "provider": "Google", | ||
| "profileArn": "arn:aws:codewhisperer:us-east-1:699475941385:profile/..." | ||
| } | ||
| ``` | ||
|
|
||
| ### Profile fallback | ||
|
|
||
| If `profileArn` is not embedded in the token file, Kiro also persists the selected profile: | ||
|
|
||
| ```json | ||
| { | ||
| "arn": "arn:aws:codewhisperer:us-east-1:699475941385:profile/...", | ||
| "name": "Google" | ||
| } | ||
| ``` | ||
|
|
||
| ## Live Refresh + Usage API | ||
|
|
||
| ### Refresh social auth token | ||
|
|
||
| ```http | ||
| POST https://prod.us-east-1.auth.desktop.kiro.dev/refreshToken | ||
| Content-Type: application/json | ||
| User-Agent: KiroIDE-<version>-<machineId> | ||
| ``` | ||
|
|
||
| ```json | ||
| { | ||
| "refreshToken": "<refresh_token>" | ||
| } | ||
| ``` | ||
|
|
||
| Observed refresh response fields: | ||
|
|
||
| - `accessToken` | ||
| - `refreshToken` | ||
| - `expiresIn` | ||
| - `profileArn` | ||
|
|
||
| ### Fetch usage | ||
|
|
||
| ```http | ||
| GET https://q.<region>.amazonaws.com/getUsageLimits?origin=AI_EDITOR&profileArn=<profileArn>&resourceType=AGENTIC_REQUEST | ||
| Authorization: Bearer <accessToken> | ||
| Accept: application/json | ||
| ``` | ||
|
|
||
| Extra headers used by Kiro only for specific auth modes: | ||
|
|
||
| - `TokenType: EXTERNAL_IDP` for external IdP accounts | ||
| - `redirect-for-internal: true` for internal AWS accounts | ||
|
|
||
| Observed response fields: | ||
|
|
||
| - `nextDateReset` | ||
| - `overageConfiguration.overageStatus` | ||
| - `subscriptionInfo.subscriptionTitle` | ||
| - `subscriptionInfo.type` | ||
| - `usageBreakdownList[*]` | ||
| - `userInfo.userId` | ||
|
|
||
| ## Provider Strategy in OpenUsage | ||
|
|
||
| 1. Require Kiro auth token presence so stale post-logout cache data is not shown as an active account. | ||
| 2. Read `state.vscdb` for the normalized numeric usage view. | ||
| 3. Read the latest `q-client.log` `GetUsageLimitsCommand` response for plan and overage metadata. | ||
| 4. If the local cache is missing, incomplete, or older than the app's staleness threshold, call the live refresh/API path. | ||
| 5. If live fetch fails but the local cache is usable, keep showing the last local snapshot. | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Kiro provider local-source resolution is hardcoded to macOS-only paths, so local usage/auth discovery will fail on Linux/Windows.
Prompt for AI agents