{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cybernative.ai/audit/agent-work-receipt.schema.json",
  "title": "CyberNative Agent Work Receipt",
  "description": "A metadata-first record of an AI-assisted workflow, its evidence, controls, resources, evaluation, failures, and rework. Sensitive payloads are excluded.",
  "type": "object",
  "required": ["schemaVersion", "receiptType", "generatedAt", "workflow", "privacy"],
  "properties": {
    "schemaVersion": { "const": "cybernative.agent-work-receipt/v0.2" },
    "receiptType": { "enum": ["self-assessment", "execution"] },
    "schema": { "type": "string", "format": "uri" },
    "receiptId": { "type": "string", "minLength": 8 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "source": { "type": "string" },
    "verified": { "type": "boolean" },
    "workflow": { "type": "string", "minLength": 1, "maxLength": 200 },
    "intent": { "type": "string" },
    "readiness": { "type": "string" },
    "baseline": { "type": "object" },
    "outcome": { "type": "object" },
    "runtime": { "type": "array", "items": { "type": "object" } },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["kind", "ref"],
        "properties": {
          "kind": { "type": "string" },
          "ref": { "type": "string" },
          "sha256": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" }
        },
        "additionalProperties": true
      }
    },
    "actionApprovalTrace": { "type": "array", "items": { "type": "object" } },
    "resourceUse": { "type": "object" },
    "evaluation": { "type": "object" },
    "failures": { "type": "array", "items": { "type": "object" } },
    "rework": { "type": "array", "items": { "type": "object" } },
    "authority": { "type": "object" },
    "controls": { "type": "object" },
    "requiredNextEvidence": { "type": "array", "items": { "type": "string" } },
    "privacy": { "type": "string", "minLength": 1 }
  },
  "allOf": [
    {
      "if": { "properties": { "receiptType": { "const": "execution" } }, "required": ["receiptType"] },
      "then": { "required": ["receiptId", "intent", "baseline", "outcome", "runtime", "evidence", "actionApprovalTrace", "resourceUse", "evaluation", "failures", "rework"] }
    }
  ],
  "additionalProperties": false
}
