feat: 按 Vault 隔离桌面检索投影与任务链接

This commit is contained in:
2026-09-08 15:12:25 +08:00
parent 044e6d6146
commit e9df45b7ca
13 changed files with 225 additions and 11 deletions
+22 -2
View File
@@ -26,8 +26,28 @@ def _load_extension(conn: sqlite3.Connection) -> None:
def connect() -> sqlite3.Connection:
settings = get_settings()
settings.db_path.parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(settings.db_path)
return _connect_path(settings.db_path)
def connect_knowledge() -> sqlite3.Connection:
"""Desktop projections never share note or vector rows between Vaults."""
settings = get_settings()
if settings.environment != 'desktop':
return connect()
from app import host_bridge
from app.errors import ApiError
from uuid import UUID
try:
vault = str(UUID(host_bridge.vault_id.get() or ''))
except ValueError:
raise ApiError(409, 'WORKSPACE_NOT_OPEN', '请先打开授权工作区。') from None
# This database also holds durable logical records (tasks); never delete it as a cache.
return _connect_path(settings.data_dir / 'vault-state' / vault / 'core.sqlite3')
def _connect_path(path) -> sqlite3.Connection:
path.parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(path)
conn.row_factory = sqlite3.Row
# 关闭 Python sqlite3 的隐式事务,提交时机由 transaction() 或显式 commit 控制。
conn.isolation_level = None