#608

core: move the shared-readings store out of agent-usage into tc::readings

Openwiiiimmopened 13d ago

Move the store, lease and caching code stealth-factory/opscope#613 built inside agent-usage into opscope-core, unchanged, so other widgets can use it.

Context / problem

Everything stealth-factory/opscope#613 built lives in widgets/src/widgets/agent-usage/. lease.rs and sharing.rs use no agent-usage types except one path helper. The reading half of Caches in shared.rs is tied to agent-usage. Part of stealth-factory/opscope#630.

Scope

In:

  • core/src/readings/ with the lease and store code, used as tc::readings.
  • agent-usage's Caches embeds tc::readings::Cache. cached(), cached_file(), remember_refusal() and kept() stay as thin wrappers.
  • The store path goes through tc::state_dir().
  • check.rs: add account_tag, held_for and backoff to the helpers widgets may not redefine.
  • A section in docs/internals.md.

Out:

  • Any new behaviour, key change or schema change. That is the next issue.

Acceptance

  • agent-usage uses the same file name, schema and key strings, so an old and a new agent-usage keep sharing. A test opens a store written by the old code.
  • Every existing lease, store and held_for test passes from core.
  • cargo test passes on Linux and on macOS.
  • The PR states the binary size change and that ldd is unchanged.
Agent notes
  • agent-usage computes its own state path (claude.rs snapshot_state_home). It differs from tc::state_dir() only when XDG_STATE_HOME is set but empty, or HOME is unset. Make sure the file name stays agent-usage.sqlite in the same directory.
  • About 40 direct uses of caches.live, .good, .fails outside shared.rs need a field-path change.
  • rusqlite (bundled) and sha2 are already core dependencies, so no crate is added.

Activity

2
linear-code[bot]13d ago
coderabbitai[bot]13d ago
🔗 Related PRs

stealth-factory/opscope#619 - feat(agent-usage): share vendor readings across panes (OPS-274) [merged] stealth-factory/opscope#485 - perf(agent-usage): read logs less, less often - windowed, gated, budgeted and persisted (OPS-208) [merged]


📝 Issue Planner

Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

  • Create Plan

🧪 Issue enrichment is currently in open beta.

You can configure auto-planning by selecting labels in the issue_enrichment configuration.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

💬 Have feedback or questions? Drop into our discord!