052591281d
- Complete agent system with planning and execution - Bridge API with FastAPI server - WhatsApp-style mobile dashboard - Enhanced web search with query improvement - Security guards and policy checks - Comprehensive documentation
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
"""Append-only JSONL audit logger for Bridge runs."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
from typing import Any, Optional
|
|
|
|
|
|
def _now() -> str:
|
|
return datetime.now(timezone.utc).isoformat()
|
|
|
|
|
|
class BridgeAuditLogger:
|
|
"""Writes one JSON record per line to runs/<run_id>/audit.jsonl."""
|
|
|
|
def __init__(self, run_id: str, runs_dir: Path, trace_id: Optional[str] = None) -> None:
|
|
self._run_id = run_id
|
|
self._trace_id = trace_id
|
|
self._path = runs_dir / run_id / "audit.jsonl"
|
|
self._path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
def log(
|
|
self,
|
|
event_type: str,
|
|
*,
|
|
step_id: Optional[str] = None,
|
|
status: str = "ok",
|
|
details: Optional[dict[str, Any]] = None,
|
|
) -> None:
|
|
record = {
|
|
"timestamp": _now(),
|
|
"trace_id": self._trace_id,
|
|
"run_id": self._run_id,
|
|
"layer": "bridge",
|
|
"event_type": event_type,
|
|
"step_id": step_id,
|
|
"status": status,
|
|
"details": details or {},
|
|
}
|
|
with self._path.open("a", encoding="utf-8") as f:
|
|
f.write(json.dumps(record) + "\n")
|