"""Audit log for Cursor delegations.""" from __future__ import annotations import json from datetime import datetime, timezone from pathlib import Path from typing import Any from cursor_mcp.config import settings def audit_log(event: str, payload: dict[str, Any]) -> None: path = Path(settings.audit_log_path).expanduser() path.parent.mkdir(parents=True, exist_ok=True) record = { "ts": datetime.now(timezone.utc).isoformat(), "event": event, **payload, } with path.open("a", encoding="utf-8") as fh: fh.write(json.dumps(record, default=str) + "\n")