| 50 | return _state_from_dict(data) |
| 51 | |
| 52 | def save(self, state: MemoryPolicyState, reason: str = "update") -> None: |
| 53 | self.path.parent.mkdir(parents=True, exist_ok=True) |
| 54 | self.path.write_text( |
| 55 | json.dumps(asdict(state), indent=2, ensure_ascii=False, sort_keys=True), |
| 56 | encoding="utf-8", |
| 57 | ) |
| 58 | revision = MemoryPolicyRevision(timestamp=_utc_now_iso(), reason=reason, state=state) |
| 59 | with self.history_path.open("a", encoding="utf-8") as handle: |
| 60 | handle.write(json.dumps(_revision_to_dict(revision), ensure_ascii=False) + "\n") |
| 61 | |
| 62 | def history(self) -> list[MemoryPolicyRevision]: |
| 63 | if not self.history_path.exists(): |