{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "provenancecode.tap.v1",
  "title": "ProvenanceCode Task Attestation/Provenance (TAP v1.0)",
  "description": "Schema for TAP records — the authoritative, machine-verifiable artifact for a single agent task execution. Runtime governance track, ProvenanceCode Standard v2.0.",
  "type": "object",
  "required": [
    "schema",
    "id",
    "title",
    "version",
    "lifecycle",
    "timestamps",
    "runtime",
    "git",
    "actors",
    "task",
    "risk",
    "enforcement"
  ],
  "additionalProperties": true,
  "properties": {
    "schema": {
      "type": "string",
      "const": "provenancecode.tap.v1"
    },
    "id": {
      "type": "string",
      "description": "TAP ID in simple (TAP-000001) or hierarchical (TAP-PROJ-SUB-000001) format",
      "pattern": "^TAP-([A-Z0-9]{2,8}(-[A-Z0-9]{2,8})?-[0-9]{6}|[0-9]{6})$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "lifecycle": {
      "type": "object",
      "required": ["state"],
      "additionalProperties": true,
      "properties": {
        "state": {
          "type": "string",
          "enum": ["in_progress", "completed", "blocked", "failed", "superseded"]
        },
        "supersedes": {
          "type": ["string", "null"]
        },
        "superseded_by": {
          "type": ["string", "null"]
        }
      }
    },
    "timestamps": {
      "type": "object",
      "required": ["started_at", "ended_at"],
      "additionalProperties": true,
      "properties": {
        "started_at": {
          "type": "string",
          "format": "date-time"
        },
        "ended_at": {
          "type": ["string", "null"],
          "format": "date-time"
        },
        "attested_at": {
          "type": ["string", "null"],
          "format": "date-time"
        }
      }
    },
    "runtime": {
      "type": "object",
      "required": ["agent", "model"],
      "additionalProperties": true,
      "properties": {
        "agent": {
          "type": "string",
          "minLength": 1,
          "description": "The AI agent or tool executing the task (e.g. cursor, copilot, claude-code)"
        },
        "model": {
          "type": "string",
          "minLength": 1
        },
        "session_id": {
          "type": ["string", "null"]
        },
        "conversation_id": {
          "type": ["string", "null"]
        }
      }
    },
    "git": {
      "type": "object",
      "required": ["branch", "commit_sha"],
      "additionalProperties": true,
      "properties": {
        "repo": {
          "type": "string"
        },
        "branch": {
          "type": "string",
          "minLength": 1
        },
        "commit_sha": {
          "type": "string",
          "pattern": "^[0-9a-f]{7,40}$"
        },
        "changed_files": {
          "type": "array",
          "items": { "type": "string" }
        },
        "pr_url": {
          "type": ["string", "null"]
        }
      }
    },
    "actors": {
      "type": "object",
      "required": ["agent", "model"],
      "additionalProperties": true,
      "properties": {
        "agent": {
          "type": "string",
          "minLength": 1
        },
        "model": {
          "type": "string",
          "minLength": 1
        },
        "human_reviewer": {
          "type": ["string", "null"]
        },
        "approvers": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "task": {
      "type": "object",
      "required": ["outcome"],
      "additionalProperties": true,
      "properties": {
        "description": {
          "type": "string"
        },
        "outcome": {
          "type": "string",
          "enum": ["succeeded", "failed", "blocked", "partial"]
        },
        "summary": {
          "type": "string"
        },
        "tools_used": {
          "type": "array",
          "items": { "type": "string" }
        },
        "tool_call_count": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "risk": {
      "type": "object",
      "required": ["needs_human_review"],
      "additionalProperties": true,
      "properties": {
        "level": {
          "type": "string",
          "enum": ["low", "medium", "high", "critical"]
        },
        "open_risks": {
          "type": "integer",
          "minimum": 0
        },
        "high_or_critical_open": {
          "type": "integer",
          "minimum": 0
        },
        "needs_human_review": {
          "type": "boolean"
        }
      }
    },
    "enforcement": {
      "type": "object",
      "required": ["validated"],
      "additionalProperties": true,
      "properties": {
        "validated": {
          "type": "boolean"
        },
        "validator": {
          "type": "string"
        },
        "errors": {
          "type": "array",
          "items": { "type": "string" }
        },
        "preset": {
          "type": "string",
          "enum": ["light", "standard", "regulated"]
        }
      }
    },
    "links": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "decisions": {
          "type": "array",
          "items": { "type": "string", "pattern": "^DEC-" }
        },
        "risks": {
          "type": "array",
          "items": { "type": "string", "pattern": "^RA-" }
        },
        "actions": {
          "type": "array",
          "items": { "type": "string", "pattern": "^ACT-" }
        },
        "memories_read": {
          "type": "array",
          "items": { "type": "string", "pattern": "^MEO-" }
        },
        "memories_written": {
          "type": "array",
          "items": { "type": "string", "pattern": "^MEO-" }
        },
        "specs": {
          "type": "array",
          "items": { "type": "string", "pattern": "^SPEC-" }
        },
        "prior_task": {
          "type": ["string", "null"]
        },
        "parent_task": {
          "type": ["string", "null"]
        }
      }
    },
    "integrity": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "task_hash": {
          "type": ["string", "null"]
        },
        "signed": {
          "type": "boolean"
        },
        "certificate": {
          "type": ["string", "null"]
        }
      }
    }
  }
}
