{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://muthu4all.github.io/proven-autonomy/spec/schemas/track-record-event.schema.json",
  "title": "Proven Autonomy · Track Record Event",
  "description": "One entry in the append-only Track Record Ledger: an agent's proposal or action, its decision context, the human verdict, the envelope check and, once the verification window closes, the verified outcome. Corrections are new events; nothing is edited in place. Draft v0.1.",
  "type": "object",
  "required": ["spec", "event_id", "event_type", "occurred_at", "ledger", "action", "context", "level_at_time", "agent"],
  "properties": {
    "spec": { "const": "proven-autonomy/track-record-event/v0.1" },
    "event_id": { "type": "string" },
    "event_type": {
      "enum": ["proposed", "decided", "executed", "blocked-by-envelope", "sampled-review", "outcome-verified", "incident", "version-change", "level-change", "freeze"]
    },
    "occurred_at": { "type": "string", "format": "date-time" },
    "ledger": {
      "type": "object",
      "description": "Makes the ledger append-only and replayable: a sequence number and the hash of the previous entry.",
      "required": ["sequence", "prev_hash", "hash"],
      "properties": {
        "sequence": { "type": "integer", "minimum": 0 },
        "prev_hash": { "type": "string", "pattern": "^sha256:[0-9a-f]{16,64}$" },
        "hash": { "type": "string", "pattern": "^sha256:[0-9a-f]{16,64}$" }
      },
      "additionalProperties": false
    },
    "action": {
      "type": "object",
      "required": ["class", "action_id", "summary"],
      "properties": {
        "class": { "type": "string", "description": "Action class id from the autonomy policy." },
        "action_id": { "type": "string", "description": "Links every event about the same action." },
        "summary": { "type": "string" },
        "value": {
          "type": "object", "required": ["amount", "currency"],
          "properties": { "amount": { "type": "number", "minimum": 0 }, "currency": { "type": "string", "pattern": "^[A-Z]{3}$" } },
          "additionalProperties": false
        },
        "tools_called": { "type": "array", "items": { "type": "string" } },
        "reversible": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "context": {
      "type": "object",
      "required": ["id"],
      "properties": {
        "id": { "type": "string" },
        "dimensions": { "type": "object", "additionalProperties": { "type": ["string", "number", "boolean"] } },
        "decision_inputs_ref": { "type": "string", "description": "Pointer to the inputs the agent saw, kept where the data lives." }
      },
      "additionalProperties": false
    },
    "level_at_time": { "enum": ["L0", "L1", "L2", "L3", "L4", "L5"] },
    "agent": {
      "type": "object",
      "required": ["id", "model", "model_version", "prompt_version"],
      "properties": {
        "id": { "type": "string" },
        "model": { "type": "string" },
        "model_version": { "type": "string" },
        "prompt_version": { "type": "string" },
        "tool_versions": { "type": "object", "additionalProperties": { "type": "string" } },
        "canary": { "type": "boolean", "description": "True while this version is in its canary after a reset." }
      },
      "additionalProperties": false
    },
    "envelope_check": {
      "type": "object",
      "required": ["result", "enforced_by"],
      "properties": {
        "result": { "enum": ["within", "blocked", "routed-to-person"] },
        "enforced_by": { "enum": ["gateway", "tool-layer"], "description": "Never the agent itself." },
        "rule": { "type": "string" }
      },
      "additionalProperties": false
    },
    "human_verdict": {
      "type": "object",
      "required": ["verdict"],
      "properties": {
        "verdict": { "enum": ["approved", "edited", "rejected", "upheld", "overturned", "not-reviewed"] },
        "reviewer_role": { "type": "string" },
        "reviewed_at": { "type": "string", "format": "date-time" },
        "review_seconds": { "type": "number", "minimum": 0, "description": "Time spent; very short reviews at scale signal rubber-stamping." },
        "edit_summary": { "type": "string" }
      },
      "additionalProperties": false
    },
    "outcome": {
      "type": "object",
      "required": ["status", "verification_window_days", "window_closes_at", "severity"],
      "properties": {
        "status": { "enum": ["pending", "held", "reversed", "complaint", "chargeback", "incident", "ambiguous"] },
        "verification_window_days": { "type": "integer", "minimum": 1 },
        "window_closes_at": { "type": "string", "format": "date-time" },
        "verified_at": { "type": "string", "format": "date-time" },
        "counted": { "enum": ["at-once", "at-window-close"], "description": "Bad news counts at once; good news counts when the window closes." },
        "severity": { "enum": ["none", "low", "medium", "high", "critical"] },
        "evidence_ref": { "type": "string" },
        "notes": { "type": "string" }
      },
      "additionalProperties": false
    },
    "triggered": {
      "type": "array",
      "description": "Demotion triggers this event fired, by id from the policy.",
      "items": { "type": "string" }
    }
  },
  "allOf": [
    { "if": { "properties": { "event_type": { "const": "outcome-verified" } } }, "then": { "required": ["outcome"] } },
    { "if": { "properties": { "event_type": { "const": "incident" } } }, "then": { "required": ["outcome"] } },
    { "if": { "properties": { "event_type": { "const": "decided" } } }, "then": { "required": ["human_verdict"] } },
    { "if": { "properties": { "event_type": { "const": "sampled-review" } } }, "then": { "required": ["human_verdict"] } },
    { "if": { "properties": { "event_type": { "enum": ["executed", "blocked-by-envelope"] } } }, "then": { "required": ["envelope_check"] } }
  ],
  "additionalProperties": false
}
