forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_review.py
More file actions
61 lines (55 loc) · 2.53 KB
/
Copy pathmemory_review.py
File metadata and controls
61 lines (55 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Pure contract for deterministic canonical-memory review queue records."""
from __future__ import annotations
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional
def build_memory_review_conflict(
*,
fact: Dict[str, Any],
conflict_with: List[str],
authority: Optional[str] = None,
source_commit_id: Optional[str] = None,
source_item_revision: Optional[int] = None,
source_content_hash: Optional[str] = None,
source_short_term_id: Optional[str] = None,
impact: Optional[float] = None,
ttl_hours: int = 72,
now: Optional[datetime] = None,
) -> Dict[str, Any]:
"""Build the stable document written by both legacy and canonical review paths."""
current_time = now or datetime.now(timezone.utc)
if current_time.tzinfo is None or current_time.utcoffset() is None:
raise ValueError("review conflict timestamp must be timezone-aware")
fact_id = str(fact.get("id") or "").strip()
if not fact_id:
raise ValueError("review conflict requires fact.id")
if authority == "canonical_memory" and (
not source_commit_id or source_item_revision is None or source_item_revision < 1 or not source_content_hash
):
raise ValueError("canonical review requires an exact source commit, revision, and content hash")
conflicts = sorted({value.strip() for value in conflict_with if value and value.strip()})
revision_segment = f"r{source_item_revision}:" if authority == "canonical_memory" else ""
review_id = f"review:{fact_id}:{revision_segment}{','.join(conflicts)}"
item = {
"review_id": review_id,
"fact_id": fact_id,
"candidate": fact,
"conflict_with": conflicts,
"veracity": fact.get("veracity"),
"impact": impact if impact is not None else fact.get("importance", 0.5),
"status": "pending",
"source_commit_id": source_commit_id,
"source_short_term_id": source_short_term_id,
"created_at": current_time,
"updated_at": current_time,
"expires_at": current_time + timedelta(hours=ttl_hours),
"permitted_uses": ["answers_with_disclaimer"],
}
if authority is not None:
item["authority"] = authority
if source_item_revision is not None:
item["source_item_revision"] = source_item_revision
if source_content_hash is not None:
item["source_content_hash"] = source_content_hash
item["referenced_memory_ids"] = sorted({fact_id, *conflicts})
return item
__all__ = ["build_memory_review_conflict"]