CodeNomad/packages/tauri-app
Pascal André 9cd0b4b901
feat(stats): display service-wide activity statistics (#968)
## Behavior
Preferences gains a **Stats** section covering the **entire connected
OpenCode service**: all projects, independent clones and subsessions.
Every locale states this scope explicitly, because native project IDs
span independent clones and cannot be presented as folder-scoped.

- **Periods:** rolling 7, 30, 90 or 365 days.
- **Figures:** input, output, reasoning and cache tokens; recorded USD
cost; session, subsession, prompt and step counts; a per-model table;
daily activity.
- **Not shown:** transcripts, polling, and provider billing or quota
precision. The Usage label stays reserved for provider subscriptions.

## Boundary
- **Endpoint:** authenticated `GET /api/workspaces/:id/service-usage`
returns native `session.stats` with explicit `scope: "service"`.
  - `tools` is always `none`.
  - Periods are bounded to 366 days.
  - Project, directory and tool selectors are rejected (400).
  - A connection or workspace change during the read fails closed.
- **UI:** an in-memory display snapshot per period. It revalidates on
mount, on settled session events (`session.idle`, `session.deleted`,
prune) and on reconnect.
- **Preferences windows:** the `usage` section is added to the Electron,
Tauri and UI native allowlists.

## Validation
- Server, UI and Electron typechecks pass.
- Backend: `service-usage.test.ts` 3/3.
- Browser: dashboard, Preferences reachability, Preferences window and
startup scenarios, 5/5.
- Unit: `preferences-window.test.ts` 2/2.
- Native: `scripts/test-service-usage-native.mjs` passes on an isolated
copy of OpenCode 2.0.29. It covers a worktree, an unrelated repository
and an independent clone, with synthetic generation and a private
home/database only.

## History
This was originally #796 (8/8). Because the series was stacked, #796 was
squash-merged into the MCP Code Mode branch (#795) rather than `dev`. It
is split out here so it can land on its own. Review fixes are included:
an in-memory cache instead of `localStorage` keyed by non-persistent
workspace IDs, the status-card surface role and spacing tokens.
2026-10-15 15:04:58 +02:00
..
scripts build: ship the Linux deb from Electron and the Windows installer without a ZIP (#955) 2026-10-14 16:45:49 +02:00
src-tauri feat(stats): display service-wide activity statistics (#968) 2026-10-15 15:04:58 +02:00
tests refactor(settings): limit the shortcut manager to renderer shortcuts 2026-10-13 22:06:10 +02:00
vendor feat(tauri): signed cross-platform updates with stable and preview feeds (#786) 2026-10-14 12:18:36 +02:00
.gitignore chore: remove historical reports and generated artifacts (#857) 2026-10-06 02:25:35 +02:00
Cargo.lock feat(tauri): signed cross-platform updates with stable and preview feeds (#786) 2026-10-14 12:18:36 +02:00
Cargo.toml feat(tauri): signed cross-platform updates with stable and preview feeds (#786) 2026-10-14 12:18:36 +02:00
NOTIFICATION_BADGES.md fix(tauri): clear unread badges on native renderer termination 2026-10-07 16:32:30 +02:00
package.json feat(tauri): signed cross-platform updates with stable and preview feeds (#786) 2026-10-14 12:18:36 +02:00