Skip to content

feat(pi.token-insights): read PI-Desktop turns through the formal usage API - #51

Open
muzimu217 wants to merge 1 commit into
vastsa:mainfrom
muzimu217:feat/token-insights-usage-api
Open

muzimu217 wants to merge 1 commit into
vastsa:mainfrom
muzimu217:feat/token-insights-usage-api

Conversation

@muzimu217

Copy link
Copy Markdown
Contributor

Summary

Reads PI-Desktop turns through the formal read-only usage facts surface
(pi.usage.listTurns, host PR vastsa/PI-Desktop#503) instead of opening
pi.sqlite directly.

  • usage.read is declared in the manifest; on hosts without the surface
    the plugin falls back to the previous local read, so 0.5.0 remains
    compatible with older releases
  • soft-deleted sessions are excluded by the contract (the direct read had
    no deleted_at filter — a small accounting fix)
  • the theme, language, and appearance paths are unchanged

Implementation

  • window walk: at most 365 days per window (the contract's cap), stepping
    backward until an empty window, 8-window ceiling
  • cursor paging (1..=500) within each window; turnId dedup across page and
    window seams
  • rows map to the existing event shape; totals are the sum of the five
    counters (the contract exposes the counters, not a precomputed total)

Tests

  • manifest assertions updated: permissions now include usage.read; the
    former negative assertion (which pinned the direct-read era) is replaced
    by positive assertions on the formal contract usage
  • new unit tests: window walk with cursor paging, dedup, 8-window ceiling,
    fallback routing (hosts without the surface)
  • 14/14 passing (4× stable), full repo suite green

…ge API

The PI-Desktop host now exposes a read-only usage facts surface
(pi.usage.listTurns, host PR vastsa/PI-Desktop#503). This switches the
plugin's PI-Desktop source from reading pi.sqlite directly to that
contract: keyset-paginated completed turns in at-most-365-day windows,
walking backward until an empty window, with turnId dedup across page
and window seams.

- usage.read is declared in the manifest; on hosts without the surface
  the plugin falls back to the previous local read, so 0.5.0 stays
  compatible with older releases
- soft-deleted sessions are excluded by the contract (a small
  accounting fix over the direct read, which had no deleted_at filter)
- the theme, language, and appearance paths are unchanged

Tests: the manifest assertions move from pinning the absence of
usage.read to asserting the formal contract usage; the API adapter gets
its own unit tests (window walk, cursor paging, dedup, 8-window ceiling,
fallback routing); an on-load test's fixed sleep is replaced by polling
for the scan's terminal state, which fixes a pre-existing flake on
Node 25.
@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

@muzimu217 is attempting to deploy a commit to the vastsa's projects Team on Vercel.

A member of the Team first needs to authorize it.

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