State And Repositories
internal/state is the persistence layer for one Anyy profile. It should
hide SQL shape from gateway, runtime, dashboard, TUI, channels, and tools.
Repository Pattern
Add focused repository methods for each query or mutation. Keep SQL in state packages and return typed records.
Callers should pass context and use repository errors rather than opening their own SQLite connections.
Migrations
Schema setup and migrations live beside repository code. New tables or columns need migration SQL, repository tests, and compatibility tests where old data may exist.
Avoid changing public protocol payloads just because storage changed.
Retention
Retention code owns archive, prune, summary, raw deletion coverage, and active window checks. It must preserve evidence needed for audit and recovery.
Do not prune from prompt/context code. Use maintenance commands and repository logic.
Blob Store
Blob storage holds large payloads outside SQLite. Records reference blobs by hash or raw reference and keep bounded previews for UI/model-visible content.
Blob writes and deletions should be atomic enough that maintenance can reconcile state and raw/blob storage later.
Debug Bundles
Debug bundles and diagnostics must be bounded and redacted. They may include status, doctor output, selected metadata, and error summaries.
Never include raw secrets, OAuth tokens, channel tokens, full private messages, or unbounded provider payloads.