1 from __future__ import annotations

2

3 import typing as t

4 from dataclasses import dataclass, field

5 from pathlib import Path

6

7 from session_buddy.settings import get_settings

8

9

10 def _resolve_data_dir() -> Path:

11 settings = get_settings()

12 data_dir = settings.data_dir.expanduser()

13 return data_dir if data_dir.is_absolute() else Path.home() / data_dir

14

15

16 def default_session_buckets(data_dir: Path) -> dict[str, str]:

17 return {

18 "sessions": str(data_dir / "sessions"),

19 "checkpoints": str(data_dir / "checkpoints"),

20 "handoffs": str(data_dir / "handoffs"),

21 "test": str(data_dir / "test"),

22 }

23

24

25@dataclass(frozen=True, slots=True)

26 class ReflectionAdapterSettings:

27 database_path: Path

28 collection_name: str = "default"

29 embedding_dim: int = 384

30 distance_metric: str = "cosine"

31 enable_vss: bool = True

32 threads: int = 4

33 memory_limit: str = "2GB"

34 enable_embeddings: bool = True

35

36 @classmethod

37 def from_settings(cls) -> ReflectionAdapterSettings:

38 data_dir = _resolve_data_dir()

39 return cls(database_path=data_dir / "reflection.duckdb")

40

41

42@dataclass(frozen=True, slots=True)

43 class KnowledgeGraphAdapterSettings:

44 database_path: Path

45 graph_name: str = "session_mgmt_graph"

46 nodes_table: str = "kg_entities"

47 edges_table: str = "kg_relationships"

48 install_extensions: tuple[str, ...] = ("duckpgq",)

49

50 @classmethod

51 def from_settings(cls) -> KnowledgeGraphAdapterSettings:

52 data_dir = _resolve_data_dir()

53 return cls(database_path=data_dir / "knowledge_graph.duckdb")

54

55

56@dataclass(frozen=True, slots=True)

57 class StorageAdapterSettings:

58 default_backend: str = "file"

59 buckets: dict[str, str] = field(default_factory=dict)

60 local_path: Path = field(default_factory=_resolve_data_dir)

61

62 @classmethod

63 def from_settings(cls) -> StorageAdapterSettings:

64 data_dir = _resolve_data_dir()

65 return cls(

66 buckets=default_session_buckets(data_dir),

67 local_path=data_dir,

68 )

69

70

71@dataclass(frozen=True, slots=True)

72 class CacheAdapterSettings:

73 chunk_cache_ttl_seconds: int = 3600

74 history_cache_ttl_seconds: int = 300