Skip to content

feat(desktop): NIP-AM agent-usage archive backend + cache-read schema - #4000

Open
wpfleger96 wants to merge 1 commit into
mainfrom
duncan/agent-usage-backend
Open

feat(desktop): NIP-AM agent-usage archive backend + cache-read schema#4000
wpfleger96 wants to merge 1 commit into
mainfrom
duncan/agent-usage-backend

Conversation

@wpfleger96

Copy link
Copy Markdown
Member

What

Adds the NIP-AM agent-usage archive backend — the Rust query engine, SQLite schema and migrations, ingestion pipeline wiring, buzz-acp first-turn baseline fix, and the minimal TS contract layer. No UI is included; this PR merges first. The companion UI stack PR opens with this as its base.

Also adds M2 schema migration: turn_cache_read_tokens and cumulative_cache_read_tokens columns on agent_metric_index. These columns persist the optional NIP-AM cacheReadTokens fields (fail-closed: NULL for all pre-migration rows). cache_write_tokens is not persisted — the wire payload carries no write-side field.

Files

Area Files
Rust archive engine desktop/src-tauri/src/archive/ — agent_usage, metric_store, store_migrations, pipeline, mod, store, lib
Rust archive tests agent_usage_tests, metric_store_tests, store_migration_tests, mod_agent_metric_tests, mod_tests, store_tests
TS contract layer tauriArchive.ts, archiveSyncManager.ts + test
buzz-acp usage.rs, acp.rs, pool.rs (first-turn baseline fix)

Migration chain

M2 (additive column additions) runs before M1 (index rebuild) so the M1 rebuild always operates against the full schema. All migrations are idempotent; existing DBs get NULL for the new columns.

Stack

Stack: this PRagent-usage-ui

Review note

The archive engine and buzz-acp content was reviewed at 3d6c9c413 (PR #2035, 9/9/9). The only addition relative to the reviewed tree is the M2 cache-column migration. Equivalence: tree diff between stack tip and 3d6c9c413 touches only the 6 files in desktop/src-tauri/src/archive/ that constitute the M2 addition.

Add the NIP-AM agent-usage archive backend (query engine, SQLite
migrations, ingestion pipeline, buzz-acp first-turn fix) from
PR #2035. This is the backend-only base of a stacked split; the
UI lives in the companion stack PR.

Backend surface:
- `desktop/src-tauri/src/archive/`: archive query engine, metric
  index store, store migrations, pipeline integration, and full
  Rust test suite (agent_usage, metric_store, store, migration tests)
- `desktop/src/shared/api/tauriArchive.ts`: wire types + Tauri
  command bridge (`get_agent_usage_series`)
- `desktop/src/features/local-archive/archiveSyncManager.ts`:
  `persistedAgentMetrics` notifier wired to the archiveSyncManager
- `crates/buzz-acp/`: first-turn baseline fix (Task E from #2035)

Cache-read schema addition (M2 migration):
Adds `turn_cache_read_tokens` and `cumulative_cache_read_tokens`
columns to `agent_metric_index` via a new one-shot additive migration
(M2). These columns persist the optional NIP-AM `cacheReadTokens`
fields so that Hayt's Phase-0 cache-threading events (crates/buzz-acp,
separate PR) start being persisted the day both PRs merge. All
pre-migration rows receive NULL (fail-closed). M2 runs before M1 in
the migration chain so the M1 rebuild always operates against the
full schema. Three M2 migration tests: fresh DB, post-M1 upgrade, and
idempotency.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
@wpfleger96
wpfleger96 force-pushed the duncan/agent-usage-backend branch from 635b030 to 39e1a91 Compare August 3, 2026 18:56
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