Skip to content

feat: add Amazon Quick local token usage provider - #316

Open
solangegamboa wants to merge 1 commit into
chattymin:mainfrom
solangegamboa:feat/aws-q-provider-multi-session
Open

solangegamboa wants to merge 1 commit into
chattymin:mainfrom
solangegamboa:feat/aws-q-provider-multi-session

Conversation

@solangegamboa

Copy link
Copy Markdown

Summary

Add local token-usage support for Amazon Quick (Quick Suite — Amazon's desktop AI assistant for macOS/Windows) through the existing provider-agnostic aggregation pipeline.

  • Discover ~/.quickwork/sessions/sessions.db (single-profile installs) and ~/.quickwork/profiles/*/sessions/sessions.db (enterprise/team installs), plus optional custom scan roots, de-duplicating resolved database paths.
  • Read turn-level usage with read-only SQLite connections. Only usage metadata is selected (event id, timestamp, token_usage, model); conversation bodies (full_content, session_messages.content) and credentials are never read.
  • Parse real per-turn counts from message_assistant_complete events, whose data JSON carries a token_usage object with input_tokens / output_tokens / cache_read_tokens / cache_write_tokens. This is source-recorded usage, not the byte estimate Kiro falls back to.
  • A single database holds every session (the session_id column separates them), so multi-session totals are the natural sum of all events — no per-session file scanning. Multiple profiles are all scanned.
  • Sit on the shared LocalAdditionalUsageCache like Kiro/Aside: one scan per refresh feeds daily and enrichment, and each scan merges with previously-seen entries (dedupKeepMax(existing + loaded)). Deleting a session removes its events, so a plain rescan would make today's total go down; the merge keeps already-counted usage until the cache resets.
  • The reader never throws. Unreadable databases (a foreign sessions.db under a custom root, a busy WAL recovery) are skipped; an all-failed rescan returns [], which the merge treats as "nothing new" rather than zero usage.
  • Entry ids carry the file's inode so a recreated profile cannot hide its new events behind cached ids.
  • Register QUICKWORK_HOME as a location override and include Amazon Quick in daily/weekly/monthly/active-block aggregation while preserving existing providers.
  • Add synthetic SQLite tests (real session_events schema) and update the provider-registration and tab-layout guards.

Type of change

  • New feature

Data semantics and limitations

  • Usage is attributed to the local date of the turn's completion timestamp, so tokens land in the day / 5-hour block they were generated in.
  • Zero-token turns (aborted before a response) are dropped, so they never form an empty active block or a Quick tab with nothing in it.
  • The token_usage.model field is Quick's plan-mode label ("balanced", etc.), not a public price-table model, so cost is marked unavailable rather than priced against an unrelated model.
  • A deleted session's already-counted usage stays counted until the scan cache is dropped (Settings save, month rollover, relaunch), matching Kiro/Aside behavior.
  • This adds local usage accounting, not subscription-limit tracking.

UI changes

None. The existing provider tab and aggregates display Amazon Quick automatically once data is present.

Validation

  • swift build and full swift test pass locally: 1088 tests, 12 skipped, 0 failures. The 10 new AmazonQuickUsageTests cover bucket parsing, multi-session summation in one DB, multi-profile + single-profile summation, the type filter, timestamp→local-day attribution, zero-token drop, unreadable-DB skip, malformed-JSON skip, provider registration + custom-root support, and shared-scan enrichment totals.
  • Read-only probe of a live Amazon Quick store confirmed the parser reproduces the SQL reference exactly: overall 502,798,367 tokens across 9,035 usage entries (9,042 message_assistant_complete rows minus 7 zero-token aborted turns) and today's 1,580,845, matching a json_extract sum over the same events. No personal database or diagnostic snapshot is included in this PR.

Checklist

  • swift build and swift test pass locally
  • PR title and description are written in English
  • No UI source changes; the existing provider tab and aggregates display Amazon Quick
  • No copyrighted assets, secrets, or private tooling references are committed
  • Tests were added or updated for this change

Reads real per-turn token_usage (input/output/cache read/write) from
message_assistant_complete events in ~/.quickwork sessions.db. A single
database holds every session, so multi-session totals are the natural sum;
enterprise/team installs with multiple profiles are all scanned. Honours
$QUICKWORK_HOME and custom scan roots. Aborted zero-token turns dropped;
deleted sessions stay counted until the scan cache resets (Kiro/Aside policy).

Validated against real local data: overall 502,798,367 tokens and today's
1,580,845 match the SQL reference exactly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant