Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added gateway/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions gateway/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Gateway handlers for evidence persistence."""

from __future__ import annotations

import json
from pathlib import Path
from typing import Mapping

from hc_agent.core.evidence import build_min_evidence


def write_evidence_json(evidence: Mapping[str, object], output_dir: str | Path) -> Path:
"""Write minimal evidence payload to evidence.json and return its path."""
output_path = Path(output_dir) / "evidence.json"
minimal_evidence = build_min_evidence(evidence)

output_path.write_text(
json.dumps(minimal_evidence, indent=2, sort_keys=True) + "\n",
encoding="utf-8",
)
return output_path
Empty file added hc_agent/__init__.py
Empty file.
Empty file added hc_agent/core/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions hc_agent/core/evidence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Evidence filtering helpers."""

from __future__ import annotations

from typing import Mapping

ALLOWED_EVIDENCE_KEYS: tuple[str, ...] = (
"service",
"endpoint",
"method",
"path",
"status",
"request_id",
"duration_ms",
"signature_sha256",
)


def build_min_evidence(evidence: Mapping[str, object] | None) -> dict[str, object]:
"""Return a minimal evidence payload containing only allowed keys."""
if not evidence:
return {}

return {
key: evidence[key]
for key in ALLOWED_EVIDENCE_KEYS
if key in evidence
}