Coverage for src/governed_harness/memory/context.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-12 16:06 +0000

1from __future__ import annotations 

2 

3from governed_harness.domain.models import MemoryRecord 

4from governed_harness.evidence.hashing import sha256_json 

5 

6from .store import MemoryExclusion 

7 

8 

9def context_manifest( 

10 records: tuple[MemoryRecord, ...], exclusions: tuple[MemoryExclusion, ...] = () 

11) -> dict[str, object]: 

12 """Manifest of the memory applied to an execution. 

13 

14 The digest covers the records that entered the context. Excluded candidates are listed with 

15 their reason so that the absence of a record is auditable too. The value of a record marked 

16 as sensitive is withheld: the manifest is evidence and reaches the agent provider. 

17 """ 

18 items = [ 

19 { 

20 "memoryId": item.memory_id, 

21 "level": item.level, 

22 "key": item.key, 

23 "value": None if item.sensitive else item.value, 

24 "provenance": item.provenance.model_dump(mode="json", by_alias=True), 

25 **({"sensitive": True} if item.sensitive else {}), 

26 } 

27 for item in records 

28 ] 

29 excluded = [ 

30 { 

31 "memoryId": item.memory_id, 

32 "level": item.level, 

33 "key": item.key, 

34 "reason": item.reason, 

35 **({"supersededBy": item.superseded_by} if item.superseded_by else {}), 

36 } 

37 for item in exclusions 

38 ] 

39 return {"records": items, "digest": sha256_json(items), "excluded": excluded}