-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_protocol_evidence_consumer.sample.py
More file actions
61 lines (50 loc) · 1.65 KB
/
agent_protocol_evidence_consumer.sample.py
File metadata and controls
61 lines (50 loc) · 1.65 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
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
REQUIRED_KEYS = (
"id",
"taskSeedId",
"baseCommit",
"headCommit",
"actor",
"policyVerdict",
"startTime",
"endTime",
)
def load_evidence_jsonl(path: str | Path) -> list[dict[str, Any]]:
target = Path(path)
entries: list[dict[str, Any]] = []
for raw in target.read_text(encoding="utf-8").splitlines():
if not raw.strip():
continue
entries.append(json.loads(raw))
return entries
def summarize_evidence(entries: list[dict[str, Any]]) -> dict[str, Any]:
missing: list[str] = []
for entry in entries:
for key in REQUIRED_KEYS:
if key not in entry:
missing.append(f"{entry.get('id', '<unknown>')}:{key}")
return {
"count": len(entries),
"actors": sorted({str(entry.get("actor", "")) for entry in entries if entry.get("actor")}),
"policy_verdicts": sorted(
{str(entry.get("policyVerdict", "")) for entry in entries if entry.get("policyVerdict")}
),
"missing_required_fields": missing,
}
def main() -> None:
sample_path = (
Path(__file__).resolve().parents[2]
/ "agent-protocols"
/ "examples"
/ "evidence.sample.json"
)
evidence_jsonl = Path("evidence.sample.jsonl")
if not evidence_jsonl.exists():
evidence_jsonl.write_text(sample_path.read_text(encoding="utf-8") + "\n", encoding="utf-8")
report = summarize_evidence(load_evidence_jsonl(evidence_jsonl))
print(json.dumps(report, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()