fix(vault): include shared docs in agent read paths (#917)

- Patch vault_search, ListDocuments, CountDocuments, ListTreeEntries to
  include shared docs (agent_id IS NULL) for agents in the tenant
- Keep DELETE/GetDocument/GetByBasename strict (auth-intent)
- Add CHECK invariant vault_documents_scope_consistency (PG migration
  000055 NOT VALID, SQLite triggers v24) to prevent future drift
- Update docs and changelog

Affects PostgreSQL and SQLite (desktop edition).
This commit is contained in:
viettranx committed 2026-04-16 14:17:48 +07:00
1 parent 4fe293ae1e
commit 7cfcbbf9db
17 files changed
+1412 -16

No files matched your search

+7 -1
View File
@@ -1531,7 +1531,13 @@ CREATE TABLE IF NOT EXISTS vault_documents (
summary TEXT NOT NULL DEFAULT '',
metadata TEXT DEFAULT '{}',
created_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
updated_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))
updated_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
CONSTRAINT vault_documents_scope_consistency CHECK (
(scope = 'personal' AND agent_id IS NOT NULL AND team_id IS NULL) OR
(scope = 'team' AND team_id IS NOT NULL AND agent_id IS NULL) OR
(scope = 'shared' AND agent_id IS NULL AND team_id IS NULL) OR
scope = 'custom'
)
);
-- SQLite prohibits expressions in inline UNIQUE constraints; use a unique index instead.
CREATE UNIQUE INDEX IF NOT EXISTS idx_vault_docs_unique_path