feat(archive): add agent turn-metric (kind 44200) local archive

Subscribe to all owned agents' turn-metric events (kind 44200) as a
special case of the #1442 local-save archive primitive. Mirrors the
observer-feed (24200) wiring but uses the persistent /query proof path
since the relay stores and #p-gates 44200 events.

Key design decisions:
- owner_p+44200 routes to the persistent bucket (relay is source of
  truth); owner_p+24200 stays on the ephemeral path unchanged.
- Decrypt at ingest (NIP-44, agent→owner); store plaintext payload JSON
  so token-usage calculators can read archive.db directly without the
  owner key. Fail-closed: decrypt error → drop, never store ciphertext.
- owner_p filter arm added to plan_archive: {ids, #p, kinds}.
- Both seed hooks (observer + metric) now merge existing owner_p kinds
  before upserting, preventing concurrent first-run seeds from clobbering
  each other. Observer toggle likewise merges rather than stomping.
- Build-time flag BUZZ_BUILD_AGENT_METRIC_ARCHIVE_DEFAULT (presence
  remap → BUZZ_DESKTOP_BUILD_AGENT_METRIC_ARCHIVE_DEFAULT=1); default
  off for OSS, baked on for internal builds via buzz-releases.
- Separate toggle in LocalArchiveSettingsCard with its own enabled state.
- KIND_AGENT_TURN_METRIC = 44200 added to kinds.ts.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
2026-07-06 17:17:19 -04:00
parent 7110788077
commit 52ec97fd9d
15 changed files with 884 additions and 34 deletions

View File

@@ -69,7 +69,11 @@ const overrides = new Map([
// E2E test-depth hardening added the owner_p content round-trip assert and
// two empty-table drop asserts (~24 lines). Queued to split the test module
// into archive/mod_tests.rs in a follow-up.
["src-tauri/src/archive/mod.rs", 1465],
// agent-metric-archive PR added 4 new unit tests (owner_p+44200 routing,
// decrypt-success plaintext storage, decrypt-fail-closed, 24200 still
// ephemeral) + run_batch_sync_with_keys helper (~175 lines). Same test-growth
// category as above. Still queued to split.
["src-tauri/src/archive/mod.rs", 1670],
["src-tauri/src/commands/agents.rs", 1437],
// #1418 read-path fix: get_thread_replies' blocker fix (shared TIMELINE_KINDS
// const + build_thread_replies_filter helper, mirroring the channel sibling so