hakua-memory 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hakua_memory/__init__.py +21 -0
- hakua_memory/composite.py +257 -0
- hakua_memory/config.py +168 -0
- hakua_memory/ebbinghaus/__init__.py +862 -0
- hakua_memory/ebbinghaus/experience.py +1488 -0
- hakua_memory/ebbinghaus/migrations.py +362 -0
- hakua_memory/ebbinghaus/models.py +85 -0
- hakua_memory/ebbinghaus/policies.py +529 -0
- hakua_memory/ebbinghaus/semantic_graph_bridge.py +764 -0
- hakua_memory/ebbinghaus/store.py +2736 -0
- hakua_memory/obsidian/__init__.py +32 -0
- hakua_memory/obsidian/templates.py +212 -0
- hakua_memory/rag/__init__.py +36 -0
- hakua_memory/rag/chunking.py +150 -0
- hakua_memory/rag/contradiction.py +228 -0
- hakua_memory/rag/ingestion.py +260 -0
- hakua_memory/rag/meeting.py +150 -0
- hakua_memory/rag/models.py +156 -0
- hakua_memory/rag/retrieval.py +235 -0
- hakua_memory/rag/schema.py +159 -0
- hakua_memory/rag/store.py +539 -0
- hakua_memory/semantic_graph/__init__.py +23 -0
- hakua_memory/semantic_graph/cli.py +161 -0
- hakua_memory/semantic_graph/cognitive.py +174 -0
- hakua_memory/semantic_graph/config.py +273 -0
- hakua_memory/semantic_graph/embedding/__init__.py +45 -0
- hakua_memory/semantic_graph/embedding/base.py +57 -0
- hakua_memory/semantic_graph/embedding/fake.py +78 -0
- hakua_memory/semantic_graph/embedding/llama_cpp.py +221 -0
- hakua_memory/semantic_graph/embedding/serializer.py +65 -0
- hakua_memory/semantic_graph/embedding/vectors.py +144 -0
- hakua_memory/semantic_graph/exporter.py +132 -0
- hakua_memory/semantic_graph/fusion.py +85 -0
- hakua_memory/semantic_graph/graph.py +480 -0
- hakua_memory/semantic_graph/inference.py +103 -0
- hakua_memory/semantic_graph/models.py +156 -0
- hakua_memory/semantic_graph/retrieval.py +235 -0
- hakua_memory/semantic_graph/runtime.py +1185 -0
- hakua_memory/semantic_graph/sanitize.py +164 -0
- hakua_memory/semantic_graph/schemas.py +462 -0
- hakua_memory/semantic_graph/store.py +1533 -0
- hakua_memory-0.2.0.dist-info/METADATA +238 -0
- hakua_memory-0.2.0.dist-info/RECORD +46 -0
- hakua_memory-0.2.0.dist-info/WHEEL +5 -0
- hakua_memory-0.2.0.dist-info/licenses/LICENSE +201 -0
- hakua_memory-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
"""Validated immutable policies for bounded Ebbinghaus memory."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Any, Iterable, Sequence
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PolicyConfigError(ValueError):
|
|
10
|
+
"""Raised when plugin/config values are unsafe or inconsistent."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _clamp01(value: float, *, name: str) -> float:
|
|
14
|
+
number = float(value)
|
|
15
|
+
if number < 0.0 or number > 1.0:
|
|
16
|
+
raise PolicyConfigError(f"{name} must be in [0.0, 1.0], got {number}")
|
|
17
|
+
return number
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _positive_int(value: Any, *, name: str, minimum: int = 1) -> int:
|
|
21
|
+
number = int(value)
|
|
22
|
+
if number < minimum:
|
|
23
|
+
raise PolicyConfigError(f"{name} must be >= {minimum}, got {number}")
|
|
24
|
+
return number
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _as_tag_list(raw: Any) -> tuple[str, ...]:
|
|
28
|
+
if raw is None:
|
|
29
|
+
return ()
|
|
30
|
+
if isinstance(raw, str):
|
|
31
|
+
items = [part.strip().lower() for part in raw.replace(";", ",").split(",")]
|
|
32
|
+
elif isinstance(raw, Iterable):
|
|
33
|
+
items = [str(item).strip().lower() for item in raw]
|
|
34
|
+
else:
|
|
35
|
+
items = [str(raw).strip().lower()]
|
|
36
|
+
cleaned: list[str] = []
|
|
37
|
+
seen: set[str] = set()
|
|
38
|
+
for item in items:
|
|
39
|
+
if not item or item in seen:
|
|
40
|
+
continue
|
|
41
|
+
seen.add(item)
|
|
42
|
+
cleaned.append(item)
|
|
43
|
+
return tuple(cleaned)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class SleepPolicy:
|
|
48
|
+
rehearse_threshold: float = 0.35
|
|
49
|
+
forget_threshold: float = 0.10
|
|
50
|
+
salience_keep_threshold: float = 0.80
|
|
51
|
+
limit: int = 1000
|
|
52
|
+
prune_mode: str = "archive"
|
|
53
|
+
max_sleep_rehearsals: int = 4
|
|
54
|
+
max_negative_sleep_rehearsals: int = 1
|
|
55
|
+
negative_valence_threshold: float = -0.60
|
|
56
|
+
negative_reinforcement_multiplier: float = 0.25
|
|
57
|
+
negative_prefetch_min_score: float = 0.28
|
|
58
|
+
recent_replay_limit: int = 4
|
|
59
|
+
remote_integration_limit: int = 4
|
|
60
|
+
max_negative_replay_per_budget: int = 0
|
|
61
|
+
|
|
62
|
+
def __post_init__(self) -> None:
|
|
63
|
+
object.__setattr__(self, "rehearse_threshold", _clamp01(self.rehearse_threshold, name="rehearse_threshold"))
|
|
64
|
+
object.__setattr__(self, "forget_threshold", _clamp01(self.forget_threshold, name="forget_threshold"))
|
|
65
|
+
object.__setattr__(
|
|
66
|
+
self,
|
|
67
|
+
"salience_keep_threshold",
|
|
68
|
+
_clamp01(self.salience_keep_threshold, name="salience_keep_threshold"),
|
|
69
|
+
)
|
|
70
|
+
object.__setattr__(self, "limit", _positive_int(self.limit, name="limit"))
|
|
71
|
+
mode = str(self.prune_mode or "archive").strip().lower()
|
|
72
|
+
if mode not in {"none", "archive", "delete"}:
|
|
73
|
+
raise PolicyConfigError(f"prune_mode must be none|archive|delete, got {mode!r}")
|
|
74
|
+
object.__setattr__(self, "prune_mode", mode)
|
|
75
|
+
object.__setattr__(
|
|
76
|
+
self,
|
|
77
|
+
"max_sleep_rehearsals",
|
|
78
|
+
_positive_int(self.max_sleep_rehearsals, name="max_sleep_rehearsals", minimum=0),
|
|
79
|
+
)
|
|
80
|
+
object.__setattr__(
|
|
81
|
+
self,
|
|
82
|
+
"max_negative_sleep_rehearsals",
|
|
83
|
+
_positive_int(
|
|
84
|
+
self.max_negative_sleep_rehearsals,
|
|
85
|
+
name="max_negative_sleep_rehearsals",
|
|
86
|
+
minimum=0,
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
neg = float(self.negative_valence_threshold)
|
|
90
|
+
if neg < -1.0 or neg > 0.0:
|
|
91
|
+
raise PolicyConfigError(
|
|
92
|
+
f"negative_valence_threshold must be in [-1.0, 0.0], got {neg}"
|
|
93
|
+
)
|
|
94
|
+
object.__setattr__(self, "negative_valence_threshold", neg)
|
|
95
|
+
mult = float(self.negative_reinforcement_multiplier)
|
|
96
|
+
if mult < 0.0 or mult > 1.0:
|
|
97
|
+
raise PolicyConfigError(
|
|
98
|
+
f"negative_reinforcement_multiplier must be in [0.0, 1.0], got {mult}"
|
|
99
|
+
)
|
|
100
|
+
object.__setattr__(self, "negative_reinforcement_multiplier", mult)
|
|
101
|
+
object.__setattr__(
|
|
102
|
+
self,
|
|
103
|
+
"negative_prefetch_min_score",
|
|
104
|
+
_clamp01(self.negative_prefetch_min_score, name="negative_prefetch_min_score"),
|
|
105
|
+
)
|
|
106
|
+
recent_limit = _positive_int(
|
|
107
|
+
self.recent_replay_limit,
|
|
108
|
+
name="recent_replay_limit",
|
|
109
|
+
minimum=0,
|
|
110
|
+
)
|
|
111
|
+
if recent_limit > 32:
|
|
112
|
+
raise PolicyConfigError(
|
|
113
|
+
f"recent_replay_limit must be <= 32, got {recent_limit}"
|
|
114
|
+
)
|
|
115
|
+
object.__setattr__(self, "recent_replay_limit", recent_limit)
|
|
116
|
+
remote_limit = _positive_int(
|
|
117
|
+
self.remote_integration_limit,
|
|
118
|
+
name="remote_integration_limit",
|
|
119
|
+
minimum=0,
|
|
120
|
+
)
|
|
121
|
+
if remote_limit > 32:
|
|
122
|
+
raise PolicyConfigError(
|
|
123
|
+
f"remote_integration_limit must be <= 32, got {remote_limit}"
|
|
124
|
+
)
|
|
125
|
+
object.__setattr__(self, "remote_integration_limit", remote_limit)
|
|
126
|
+
negative_limit = _positive_int(
|
|
127
|
+
self.max_negative_replay_per_budget,
|
|
128
|
+
name="max_negative_replay_per_budget",
|
|
129
|
+
minimum=0,
|
|
130
|
+
)
|
|
131
|
+
if negative_limit > max(recent_limit, remote_limit):
|
|
132
|
+
raise PolicyConfigError(
|
|
133
|
+
"max_negative_replay_per_budget must not exceed either enabled "
|
|
134
|
+
f"replay budget, got {negative_limit}"
|
|
135
|
+
)
|
|
136
|
+
object.__setattr__(
|
|
137
|
+
self,
|
|
138
|
+
"max_negative_replay_per_budget",
|
|
139
|
+
negative_limit,
|
|
140
|
+
)
|
|
141
|
+
if self.forget_threshold >= self.rehearse_threshold:
|
|
142
|
+
raise PolicyConfigError(
|
|
143
|
+
"forget_threshold must be < rehearse_threshold "
|
|
144
|
+
f"({self.forget_threshold} >= {self.rehearse_threshold})"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
@classmethod
|
|
148
|
+
def from_mapping(cls, raw: dict[str, Any] | None, *, defaults: "SleepPolicy | None" = None) -> "SleepPolicy":
|
|
149
|
+
base = defaults or cls()
|
|
150
|
+
data = dict(raw or {})
|
|
151
|
+
return cls(
|
|
152
|
+
rehearse_threshold=float(data.get("rehearse_threshold", base.rehearse_threshold)),
|
|
153
|
+
forget_threshold=float(data.get("forget_threshold", base.forget_threshold)),
|
|
154
|
+
salience_keep_threshold=float(
|
|
155
|
+
data.get("salience_keep_threshold", base.salience_keep_threshold)
|
|
156
|
+
),
|
|
157
|
+
limit=int(data.get("limit", base.limit)),
|
|
158
|
+
prune_mode=str(data.get("prune_mode", base.prune_mode)),
|
|
159
|
+
max_sleep_rehearsals=int(data.get("max_sleep_rehearsals", base.max_sleep_rehearsals)),
|
|
160
|
+
max_negative_sleep_rehearsals=int(
|
|
161
|
+
data.get("max_negative_sleep_rehearsals", base.max_negative_sleep_rehearsals)
|
|
162
|
+
),
|
|
163
|
+
negative_valence_threshold=float(
|
|
164
|
+
data.get("negative_valence_threshold", base.negative_valence_threshold)
|
|
165
|
+
),
|
|
166
|
+
negative_reinforcement_multiplier=float(
|
|
167
|
+
data.get(
|
|
168
|
+
"negative_reinforcement_multiplier",
|
|
169
|
+
base.negative_reinforcement_multiplier,
|
|
170
|
+
)
|
|
171
|
+
),
|
|
172
|
+
negative_prefetch_min_score=float(
|
|
173
|
+
data.get("negative_prefetch_min_score", base.negative_prefetch_min_score)
|
|
174
|
+
),
|
|
175
|
+
recent_replay_limit=int(
|
|
176
|
+
data.get("recent_replay_limit", base.recent_replay_limit)
|
|
177
|
+
),
|
|
178
|
+
remote_integration_limit=int(
|
|
179
|
+
data.get(
|
|
180
|
+
"remote_integration_limit",
|
|
181
|
+
base.remote_integration_limit,
|
|
182
|
+
)
|
|
183
|
+
),
|
|
184
|
+
max_negative_replay_per_budget=int(
|
|
185
|
+
data.get(
|
|
186
|
+
"max_negative_replay_per_budget",
|
|
187
|
+
base.max_negative_replay_per_budget,
|
|
188
|
+
)
|
|
189
|
+
),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@dataclass(frozen=True)
|
|
194
|
+
class CapacityPolicy:
|
|
195
|
+
max_active_memories: int = 5000
|
|
196
|
+
max_archived_memories: int = 20000
|
|
197
|
+
archive_retention_days: int = 365
|
|
198
|
+
protected_tags: tuple[str, ...] = (
|
|
199
|
+
"pinned",
|
|
200
|
+
"safety-critical",
|
|
201
|
+
"user-profile",
|
|
202
|
+
"consent",
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
def __post_init__(self) -> None:
|
|
206
|
+
object.__setattr__(
|
|
207
|
+
self,
|
|
208
|
+
"max_active_memories",
|
|
209
|
+
_positive_int(self.max_active_memories, name="max_active_memories"),
|
|
210
|
+
)
|
|
211
|
+
object.__setattr__(
|
|
212
|
+
self,
|
|
213
|
+
"max_archived_memories",
|
|
214
|
+
_positive_int(self.max_archived_memories, name="max_archived_memories"),
|
|
215
|
+
)
|
|
216
|
+
object.__setattr__(
|
|
217
|
+
self,
|
|
218
|
+
"archive_retention_days",
|
|
219
|
+
_positive_int(self.archive_retention_days, name="archive_retention_days"),
|
|
220
|
+
)
|
|
221
|
+
tags = _as_tag_list(self.protected_tags)
|
|
222
|
+
object.__setattr__(self, "protected_tags", tags)
|
|
223
|
+
if self.max_active_memories >= self.max_active_memories + self.max_archived_memories:
|
|
224
|
+
raise PolicyConfigError("max_active_memories capacity invariant failed")
|
|
225
|
+
|
|
226
|
+
@classmethod
|
|
227
|
+
def from_mapping(cls, raw: dict[str, Any] | None) -> "CapacityPolicy":
|
|
228
|
+
data = dict(raw or {})
|
|
229
|
+
return cls(
|
|
230
|
+
max_active_memories=int(data.get("max_active_memories", 5000)),
|
|
231
|
+
max_archived_memories=int(data.get("max_archived_memories", 20000)),
|
|
232
|
+
archive_retention_days=int(data.get("archive_retention_days", 365)),
|
|
233
|
+
protected_tags=tuple(
|
|
234
|
+
data.get(
|
|
235
|
+
"protected_tags",
|
|
236
|
+
("pinned", "safety-critical", "user-profile", "consent"),
|
|
237
|
+
)
|
|
238
|
+
),
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@dataclass(frozen=True)
|
|
243
|
+
class DreamPolicy:
|
|
244
|
+
enabled: bool = True
|
|
245
|
+
candidate_limit: int = 24
|
|
246
|
+
max_clusters: int = 8
|
|
247
|
+
min_source_count: int = 2
|
|
248
|
+
negative_summary_max_valence: float = -0.20
|
|
249
|
+
archive_sources_after_apply: bool = True
|
|
250
|
+
|
|
251
|
+
def __post_init__(self) -> None:
|
|
252
|
+
object.__setattr__(self, "enabled", bool(self.enabled))
|
|
253
|
+
object.__setattr__(
|
|
254
|
+
self,
|
|
255
|
+
"candidate_limit",
|
|
256
|
+
_positive_int(self.candidate_limit, name="candidate_limit"),
|
|
257
|
+
)
|
|
258
|
+
object.__setattr__(
|
|
259
|
+
self,
|
|
260
|
+
"max_clusters",
|
|
261
|
+
_positive_int(self.max_clusters, name="max_clusters"),
|
|
262
|
+
)
|
|
263
|
+
object.__setattr__(
|
|
264
|
+
self,
|
|
265
|
+
"min_source_count",
|
|
266
|
+
_positive_int(self.min_source_count, name="min_source_count"),
|
|
267
|
+
)
|
|
268
|
+
valence = float(self.negative_summary_max_valence)
|
|
269
|
+
if valence < -1.0 or valence > 0.0:
|
|
270
|
+
raise PolicyConfigError(
|
|
271
|
+
f"negative_summary_max_valence must be in [-1.0, 0.0], got {valence}"
|
|
272
|
+
)
|
|
273
|
+
object.__setattr__(self, "negative_summary_max_valence", valence)
|
|
274
|
+
object.__setattr__(
|
|
275
|
+
self,
|
|
276
|
+
"archive_sources_after_apply",
|
|
277
|
+
bool(self.archive_sources_after_apply),
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
@classmethod
|
|
281
|
+
def from_mapping(cls, raw: dict[str, Any] | None) -> "DreamPolicy":
|
|
282
|
+
data = dict(raw or {})
|
|
283
|
+
return cls(
|
|
284
|
+
enabled=bool(data.get("enabled", True)),
|
|
285
|
+
candidate_limit=int(data.get("candidate_limit", 24)),
|
|
286
|
+
max_clusters=int(data.get("max_clusters", 8)),
|
|
287
|
+
min_source_count=int(data.get("min_source_count", 2)),
|
|
288
|
+
negative_summary_max_valence=float(
|
|
289
|
+
data.get("negative_summary_max_valence", -0.20)
|
|
290
|
+
),
|
|
291
|
+
archive_sources_after_apply=bool(
|
|
292
|
+
data.get("archive_sources_after_apply", True)
|
|
293
|
+
),
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
@dataclass(frozen=True)
|
|
298
|
+
class ExperiencePolicy:
|
|
299
|
+
enabled: bool = False
|
|
300
|
+
functional_forgetting: bool = True
|
|
301
|
+
latent_retention_threshold: float = 0.10
|
|
302
|
+
archive_retention_threshold: float = 0.03
|
|
303
|
+
latent_archive_after_days: int = 30
|
|
304
|
+
rescue_enabled: bool = True
|
|
305
|
+
rescue_min_score: float = 0.24
|
|
306
|
+
miss_resolution_days: int = 90
|
|
307
|
+
record_query_excerpt: bool = False
|
|
308
|
+
record_hits: bool = False
|
|
309
|
+
max_unresolved_misses: int = 2000
|
|
310
|
+
resolved_attempt_retention_days: int = 90
|
|
311
|
+
correction_rehearsals_per_sleep: int = 10
|
|
312
|
+
|
|
313
|
+
def __post_init__(self) -> None:
|
|
314
|
+
object.__setattr__(self, "enabled", bool(self.enabled))
|
|
315
|
+
object.__setattr__(self, "functional_forgetting", bool(self.functional_forgetting))
|
|
316
|
+
latent = _clamp01(self.latent_retention_threshold, name="latent_retention_threshold")
|
|
317
|
+
archive = _clamp01(self.archive_retention_threshold, name="archive_retention_threshold")
|
|
318
|
+
if not (0.0 <= archive < latent <= 1.0):
|
|
319
|
+
raise PolicyConfigError(
|
|
320
|
+
"archive_retention_threshold must be < latent_retention_threshold "
|
|
321
|
+
f"({archive} >= {latent})"
|
|
322
|
+
)
|
|
323
|
+
object.__setattr__(self, "latent_retention_threshold", latent)
|
|
324
|
+
object.__setattr__(self, "archive_retention_threshold", archive)
|
|
325
|
+
object.__setattr__(
|
|
326
|
+
self,
|
|
327
|
+
"latent_archive_after_days",
|
|
328
|
+
_positive_int(self.latent_archive_after_days, name="latent_archive_after_days"),
|
|
329
|
+
)
|
|
330
|
+
object.__setattr__(self, "rescue_enabled", bool(self.rescue_enabled))
|
|
331
|
+
object.__setattr__(
|
|
332
|
+
self,
|
|
333
|
+
"rescue_min_score",
|
|
334
|
+
_clamp01(self.rescue_min_score, name="rescue_min_score"),
|
|
335
|
+
)
|
|
336
|
+
object.__setattr__(
|
|
337
|
+
self,
|
|
338
|
+
"miss_resolution_days",
|
|
339
|
+
_positive_int(self.miss_resolution_days, name="miss_resolution_days"),
|
|
340
|
+
)
|
|
341
|
+
object.__setattr__(self, "record_query_excerpt", bool(self.record_query_excerpt))
|
|
342
|
+
object.__setattr__(self, "record_hits", bool(self.record_hits))
|
|
343
|
+
object.__setattr__(
|
|
344
|
+
self,
|
|
345
|
+
"max_unresolved_misses",
|
|
346
|
+
_positive_int(self.max_unresolved_misses, name="max_unresolved_misses"),
|
|
347
|
+
)
|
|
348
|
+
object.__setattr__(
|
|
349
|
+
self,
|
|
350
|
+
"resolved_attempt_retention_days",
|
|
351
|
+
_positive_int(
|
|
352
|
+
self.resolved_attempt_retention_days,
|
|
353
|
+
name="resolved_attempt_retention_days",
|
|
354
|
+
),
|
|
355
|
+
)
|
|
356
|
+
object.__setattr__(
|
|
357
|
+
self,
|
|
358
|
+
"correction_rehearsals_per_sleep",
|
|
359
|
+
_positive_int(
|
|
360
|
+
self.correction_rehearsals_per_sleep,
|
|
361
|
+
name="correction_rehearsals_per_sleep",
|
|
362
|
+
minimum=0,
|
|
363
|
+
),
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
@classmethod
|
|
367
|
+
def from_mapping(cls, raw: dict[str, Any] | None) -> "ExperiencePolicy":
|
|
368
|
+
data = dict(raw or {})
|
|
369
|
+
return cls(
|
|
370
|
+
enabled=bool(data.get("enabled", False)),
|
|
371
|
+
functional_forgetting=bool(data.get("functional_forgetting", True)),
|
|
372
|
+
latent_retention_threshold=float(data.get("latent_retention_threshold", 0.10)),
|
|
373
|
+
archive_retention_threshold=float(data.get("archive_retention_threshold", 0.03)),
|
|
374
|
+
latent_archive_after_days=int(data.get("latent_archive_after_days", 30)),
|
|
375
|
+
rescue_enabled=bool(data.get("rescue_enabled", True)),
|
|
376
|
+
rescue_min_score=float(data.get("rescue_min_score", 0.24)),
|
|
377
|
+
miss_resolution_days=int(data.get("miss_resolution_days", 90)),
|
|
378
|
+
record_query_excerpt=bool(data.get("record_query_excerpt", False)),
|
|
379
|
+
record_hits=bool(data.get("record_hits", False)),
|
|
380
|
+
max_unresolved_misses=int(data.get("max_unresolved_misses", 2000)),
|
|
381
|
+
resolved_attempt_retention_days=int(
|
|
382
|
+
data.get("resolved_attempt_retention_days", 90)
|
|
383
|
+
),
|
|
384
|
+
correction_rehearsals_per_sleep=int(
|
|
385
|
+
data.get("correction_rehearsals_per_sleep", 10)
|
|
386
|
+
),
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
@dataclass(frozen=True)
|
|
391
|
+
class RevisionPolicy:
|
|
392
|
+
enabled: bool = True
|
|
393
|
+
auto_archive_superseded: bool = True
|
|
394
|
+
contest_dependents: bool = True
|
|
395
|
+
protected_revision_allowed: bool = True
|
|
396
|
+
|
|
397
|
+
def __post_init__(self) -> None:
|
|
398
|
+
object.__setattr__(self, "enabled", bool(self.enabled))
|
|
399
|
+
object.__setattr__(self, "auto_archive_superseded", bool(self.auto_archive_superseded))
|
|
400
|
+
object.__setattr__(self, "contest_dependents", bool(self.contest_dependents))
|
|
401
|
+
object.__setattr__(
|
|
402
|
+
self,
|
|
403
|
+
"protected_revision_allowed",
|
|
404
|
+
bool(self.protected_revision_allowed),
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
@classmethod
|
|
408
|
+
def from_mapping(cls, raw: dict[str, Any] | None) -> "RevisionPolicy":
|
|
409
|
+
data = dict(raw or {})
|
|
410
|
+
return cls(
|
|
411
|
+
enabled=bool(data.get("enabled", True)),
|
|
412
|
+
auto_archive_superseded=bool(data.get("auto_archive_superseded", True)),
|
|
413
|
+
contest_dependents=bool(data.get("contest_dependents", True)),
|
|
414
|
+
protected_revision_allowed=bool(data.get("protected_revision_allowed", True)),
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
@dataclass(frozen=True)
|
|
419
|
+
class InsightPolicy:
|
|
420
|
+
enabled: bool = True
|
|
421
|
+
require_validation: bool = True
|
|
422
|
+
association_limit: int = 8
|
|
423
|
+
candidate_ttl_days: int = 30
|
|
424
|
+
validation_min_confidence: float = 0.65
|
|
425
|
+
|
|
426
|
+
def __post_init__(self) -> None:
|
|
427
|
+
object.__setattr__(self, "enabled", bool(self.enabled))
|
|
428
|
+
object.__setattr__(self, "require_validation", bool(self.require_validation))
|
|
429
|
+
limit = _positive_int(self.association_limit, name="association_limit")
|
|
430
|
+
if limit > 64:
|
|
431
|
+
raise PolicyConfigError(f"association_limit must be <= 64, got {limit}")
|
|
432
|
+
object.__setattr__(self, "association_limit", limit)
|
|
433
|
+
object.__setattr__(
|
|
434
|
+
self,
|
|
435
|
+
"candidate_ttl_days",
|
|
436
|
+
_positive_int(self.candidate_ttl_days, name="candidate_ttl_days"),
|
|
437
|
+
)
|
|
438
|
+
object.__setattr__(
|
|
439
|
+
self,
|
|
440
|
+
"validation_min_confidence",
|
|
441
|
+
_clamp01(self.validation_min_confidence, name="validation_min_confidence"),
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
@classmethod
|
|
445
|
+
def from_mapping(cls, raw: dict[str, Any] | None) -> "InsightPolicy":
|
|
446
|
+
data = dict(raw or {})
|
|
447
|
+
return cls(
|
|
448
|
+
enabled=bool(data.get("enabled", True)),
|
|
449
|
+
require_validation=bool(data.get("require_validation", True)),
|
|
450
|
+
association_limit=int(data.get("association_limit", 8)),
|
|
451
|
+
candidate_ttl_days=int(data.get("candidate_ttl_days", 30)),
|
|
452
|
+
validation_min_confidence=float(data.get("validation_min_confidence", 0.65)),
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
@dataclass(frozen=True)
|
|
457
|
+
class EbbinghausPolicies:
|
|
458
|
+
base_stability_days: float = 3.0
|
|
459
|
+
decay_threshold: float = 0.10
|
|
460
|
+
max_prefetch: int = 5
|
|
461
|
+
min_prefetch_score: float = 0.18
|
|
462
|
+
auto_encode_turns: bool = False
|
|
463
|
+
sleep: SleepPolicy = field(default_factory=SleepPolicy)
|
|
464
|
+
capacity: CapacityPolicy = field(default_factory=CapacityPolicy)
|
|
465
|
+
dreaming: DreamPolicy = field(default_factory=DreamPolicy)
|
|
466
|
+
experience: ExperiencePolicy = field(default_factory=ExperiencePolicy)
|
|
467
|
+
revision: RevisionPolicy = field(default_factory=RevisionPolicy)
|
|
468
|
+
insight: InsightPolicy = field(default_factory=InsightPolicy)
|
|
469
|
+
|
|
470
|
+
def __post_init__(self) -> None:
|
|
471
|
+
base = float(self.base_stability_days)
|
|
472
|
+
if base <= 0:
|
|
473
|
+
raise PolicyConfigError("base_stability_days must be > 0")
|
|
474
|
+
object.__setattr__(self, "base_stability_days", base)
|
|
475
|
+
object.__setattr__(self, "decay_threshold", _clamp01(self.decay_threshold, name="decay_threshold"))
|
|
476
|
+
object.__setattr__(self, "max_prefetch", _positive_int(self.max_prefetch, name="max_prefetch"))
|
|
477
|
+
object.__setattr__(
|
|
478
|
+
self,
|
|
479
|
+
"min_prefetch_score",
|
|
480
|
+
_clamp01(self.min_prefetch_score, name="min_prefetch_score"),
|
|
481
|
+
)
|
|
482
|
+
object.__setattr__(self, "auto_encode_turns", bool(self.auto_encode_turns))
|
|
483
|
+
|
|
484
|
+
@classmethod
|
|
485
|
+
def from_plugin_config(cls, config: dict[str, Any] | None) -> "EbbinghausPolicies":
|
|
486
|
+
data = dict(config or {})
|
|
487
|
+
sleep_raw = data.get("sleep") if isinstance(data.get("sleep"), dict) else {}
|
|
488
|
+
capacity_raw = data.get("capacity") if isinstance(data.get("capacity"), dict) else {}
|
|
489
|
+
dream_raw = data.get("dreaming") if isinstance(data.get("dreaming"), dict) else {}
|
|
490
|
+
experience_raw = data.get("experience") if isinstance(data.get("experience"), dict) else {}
|
|
491
|
+
revision_raw = data.get("revision") if isinstance(data.get("revision"), dict) else {}
|
|
492
|
+
insight_raw = data.get("insight") if isinstance(data.get("insight"), dict) else {}
|
|
493
|
+
return cls(
|
|
494
|
+
base_stability_days=float(data.get("base_stability_days", 3.0)),
|
|
495
|
+
decay_threshold=float(data.get("decay_threshold", 0.10)),
|
|
496
|
+
max_prefetch=int(data.get("max_prefetch", 5)),
|
|
497
|
+
min_prefetch_score=float(data.get("min_prefetch_score", 0.18)),
|
|
498
|
+
auto_encode_turns=bool(data.get("auto_encode_turns", False)),
|
|
499
|
+
sleep=SleepPolicy.from_mapping(sleep_raw),
|
|
500
|
+
capacity=CapacityPolicy.from_mapping(capacity_raw),
|
|
501
|
+
dreaming=DreamPolicy.from_mapping(dream_raw),
|
|
502
|
+
experience=ExperiencePolicy.from_mapping(experience_raw),
|
|
503
|
+
revision=RevisionPolicy.from_mapping(revision_raw),
|
|
504
|
+
insight=InsightPolicy.from_mapping(insight_raw),
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
@classmethod
|
|
508
|
+
def from_config(cls, config: dict[str, Any] | None) -> "EbbinghausPolicies":
|
|
509
|
+
"""Spec-facing alias for :meth:`from_plugin_config`."""
|
|
510
|
+
return cls.from_plugin_config(config)
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
def resolve_prune_mode(*, prune: bool | None, prune_mode: str | None, default: str) -> str:
|
|
514
|
+
"""Resolve prune_mode with legacy prune=True meaning physical delete."""
|
|
515
|
+
if prune_mode is not None and str(prune_mode).strip():
|
|
516
|
+
mode = str(prune_mode).strip().lower()
|
|
517
|
+
if mode not in {"none", "archive", "delete"}:
|
|
518
|
+
raise PolicyConfigError(f"prune_mode must be none|archive|delete, got {mode!r}")
|
|
519
|
+
return mode
|
|
520
|
+
if prune is True:
|
|
521
|
+
return "delete"
|
|
522
|
+
if prune is False:
|
|
523
|
+
return "none"
|
|
524
|
+
return str(default or "archive").lower()
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def is_protected(tags: Sequence[str], protected_tags: Sequence[str]) -> bool:
|
|
528
|
+
tag_set = {str(tag).strip().lower() for tag in tags}
|
|
529
|
+
return bool(tag_set & {str(tag).strip().lower() for tag in protected_tags})
|