Skip to content

feature: local-usage-stats (1/4) - #25

Closed
myk1yt wants to merge 11 commits into
mainfrom
pr/b13-usage-store-v2
Closed

feature: local-usage-stats (1/4)#25
myk1yt wants to merge 11 commits into
mainfrom
pr/b13-usage-store-v2

Conversation

@myk1yt

@myk1yt myk1yt commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Stack Position

  • Feature Branch: feature/local-usage-stats
  • Stage: 1/4
  • Depends on: None

Description

Full Feature Description

  • Feature Branch: feature/local-usage-stats
  • Feature Name: Local Usage Statistics
  • Purpose: Resolves the problem where users cannot locally view token usage, cache effects, cost, and period-based trends by provider, and where differing usage formats across providers make consistent aggregation difficult. Provides a privacy-preserving dashboard that collects only numeric usage and non-secret identifiers locally, without collecting prompts, responses, or credentials.
  • Full Change Description: B13 adds data-minimized event/query contracts and an append-only NDJSON event store. B14 adds aggregation by date, provider, model, and mode, cache ratio, and provider-aware cost recalculation. B15 records final usage exactly once from the API attempt completion path, including success/error/cancel/retry. B16 adds transactional SQLite projection, idempotent migration, local-day rollup, query/stream IPC, stale epoch prevention, and dashboard summary/session/heatmap UI.
  • Impact Scope: Affects usage-stats.ts, src/services/stats, the provider/task capture paths Task.ts, the stats IPC usageStatsMessageHandler.ts, and the UI DashboardView.tsx and useDashboardStatsStream.ts.
  • Errors and Edge Cases: Raw events are append-only and derived rollups must be reconstructable. Duplicate idempotency keys are not re-recorded. Corrupt tails preserve the valid prefix and leave only a hash in the quarantine report instead of the original text. Migrations must be transactional/idempotent. Local day and DST boundaries are calculated per-timestamp by offset. Previous subscription epochs must not overwrite new range results. The store must not contain prompts, responses, API keys, endpoint credentials, or workspace paths.
  • Testing Method: Run contract/store, aggregation/cost, exactly-once capture, database/migration/projection/stream, IPC, dashboard reducer/component, performance, locale, and visual tests step by step. Manually create complete/cancel/retry attempts, verify event counts, then rapidly switch ranges in two dashboard windows and add events, verifying convergence without stale loading or duplicate totals. Inspect stored files to confirm no sensitive fields are present.

Why Split Into 17 PRs

Instead of submitting this feature as a single unified PR, it was split into individual PRs because as code size grows, safely reviewing a PR becomes very difficult. The feature was broken into mutually exclusive individual PRs so that each can be reviewed independently.

What This PR Specifically Changes

Adds minimal-field usage event/query contracts, append-only segmented NDJSON store, lock/queue, idempotency, rotation/hard cap, and corrupt-line quarantine. Does not include aggregation, capture, or UI.

Included Files

  • packages/types/src/usage-stats.ts
  • src/services/stats/UsageEventStore.ts
  • src/services/stats/index.ts
  • packages/types/src/__tests__/usage-stats.spec.ts
  • src/services/stats/__tests__/UsageEventStore.spec.ts

Exclusion Scope

  • Aggregation/service calculation
  • Task/provider live capture
  • Database projection/migration/IPC/dashboard
  • Prompt, response, API key, endpoint credential fields
  • All items in the common removal rules

k1yt and others added 5 commits August 2, 2026 08:27
…cit-any

Add new test file to eslint-suppressions.json with count of 26
no-explicit-any suppressions. These are standard test patterns
(mock objects, private property access via 'as any') consistent
with other test files in the suppressions list.

Fixes CI lint failure in PR #25 compile (lint) job.
@myk1yt myk1yt changed the title B13: Usage Store v2 feature: local-usage-stats (1/4) Aug 3, 2026
@myk1yt
myk1yt force-pushed the pr/b13-usage-store-v2 branch from 1ed85e5 to bae2ac9 Compare August 4, 2026 11:34
@myk1yt
myk1yt force-pushed the pr/b13-usage-store-v2 branch from d16c665 to 4ced785 Compare August 5, 2026 05:50
myk1yt pushed a commit that referenced this pull request Aug 5, 2026
…cit-any

Add new test file to eslint-suppressions.json with count of 26
no-explicit-any suppressions. These are standard test patterns
(mock objects, private property access via 'as any') consistent
with other test files in the suppressions list.

Fixes CI lint failure in PR #25 compile (lint) job.
myk1yt pushed a commit that referenced this pull request Aug 6, 2026
…cit-any

Add new test file to eslint-suppressions.json with count of 26
no-explicit-any suppressions. These are standard test patterns
(mock objects, private property access via 'as any') consistent
with other test files in the suppressions list.

Fixes CI lint failure in PR #25 compile (lint) job.
myk1yt pushed a commit that referenced this pull request Aug 6, 2026
…cit-any

Add new test file to eslint-suppressions.json with count of 26
no-explicit-any suppressions. These are standard test patterns
(mock objects, private property access via 'as any') consistent
with other test files in the suppressions list.

Fixes CI lint failure in PR #25 compile (lint) job.
@myk1yt
myk1yt force-pushed the pr/b13-usage-store-v2 branch from 00cfd91 to b1a03e3 Compare August 6, 2026 09:56
@myk1yt
myk1yt force-pushed the pr/b13-usage-store-v2 branch from 80c120f to 244e074 Compare August 6, 2026 12:44
myk1yt pushed a commit that referenced this pull request Aug 6, 2026
…cit-any

Add new test file to eslint-suppressions.json with count of 26
no-explicit-any suppressions. These are standard test patterns
(mock objects, private property access via 'as any') consistent
with other test files in the suppressions list.

Fixes CI lint failure in PR #25 compile (lint) job.
myk1yt pushed a commit that referenced this pull request Aug 6, 2026
…cit-any

Add new test file to eslint-suppressions.json with count of 26
no-explicit-any suppressions. These are standard test patterns
(mock objects, private property access via 'as any') consistent
with other test files in the suppressions list.

Fixes CI lint failure in PR #25 compile (lint) job.
@myk1yt
myk1yt force-pushed the pr/b13-usage-store-v2 branch from a6c22cc to 244e074 Compare August 7, 2026 09:19
@myk1yt myk1yt closed this Aug 7, 2026
@myk1yt
myk1yt deleted the pr/b13-usage-store-v2 branch August 7, 2026 13:06
@myk1yt
myk1yt restored the pr/b13-usage-store-v2 branch August 7, 2026 13:31
@myk1yt myk1yt reopened this Aug 8, 2026
…Org#1123)

CI failure: E2E Tests (Mocked) failed with '404 No fixture matched' because
usage-stats-store.test.ts calls startNewTask with probe tag USAGE_STATS_E2E_SMOKE
but no fixture existed.
@myk1yt

myk1yt commented Aug 10, 2026

Copy link
Copy Markdown
Owner Author

Closing to recreate with main as target base branch. This PR had stale base branch references after fork sync.

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.

2 participants