Add per-vault AI history storage#301
Conversation
|
Non-blocking: this only affects the Electron fallback path. Packaged builds should route this command through the Rust sidecar, which validates actual persisted history content. Still, for parity/hardening, the fallback should eventually mirror that behavior instead of treating any non-empty |
|
@spamsch This is ready for a review, I thought it was going to be simpler, but i was wrong, the code is not very clean, i made a lot of mistakes during implementation. The lifecycle is working fine, but I'm considering rewriting this PR. I will give it another review tomorrow with fresh eyes. I don't want to rush this until we are confident enough to merge, we do not want to break the chat history for existing users or break the migration. |
Summary
This PR adds per-vault control over where AI chat history is stored, and moves the default private storage path to local app data instead of writing chat history and pasted AI attachments into the vault by default.
Motivation
AI chat history should not be written into the vault by default because vaults may be synced, shared, backed up, or committed. This keeps private AI history device-local unless the user explicitly opts into vault storage.
The new model has two explicit storage scopes:
assets/chatfolder when the user opts into vault-backed chat history.User-facing behavior
neverwrite-file://.../ai-attachment/...preview route, without exposing arbitrary local files.Backend/storage changes
deviceandvault,AiSessionsStorageresolver so the selected scope owns the storage root decision in one place.Migration and cleanup details
Migration copies readable histories from the source scope into the destination scope and skips sessions already present in the destination. AI-owned pasted attachments are handled separately from arbitrary user files:
device -> vault: copies AI-ownedpasted-image-*attachments from app data into the vault'sassets/chatfolder and rewrites persistedfilePathreferences.vault -> device: copies AI-ownedpasted-image-*attachments from the vault into the app-data attachment namespace and rewrites persistedfilePathreferences.Safety notes
assets/chat; cleanup of device-local attachments is limited to the app-data namespace.Review focus
Manual QA focus
Tests / validation
cargo test -p neverwrite-ai persistence --libcargo test -p neverwrite-native-backend ai_pnpm --dir apps/desktop exec tsc -p tsconfig.json --noEmitpnpm --dir apps/desktop exec vitest run src/features/settings/SettingsPanel.test.tsx src/features/ai/components/AIChatMessageItem.test.tsx