{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/Eskasia/agent-governance-starter/schemas/source-lock.schema.json",
  "title": "Agent Governance External Source Lock",
  "description": "Pinned provenance for external metadata, adaptations, and copied material.",
  "type": "object",
  "required": [
    "schemaVersion",
    "sources"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "sources": {
      "type": "array",
      "maxItems": 256,
      "items": {
        "$ref": "#/$defs/source"
      }
    }
  },
  "$defs": {
    "portableRelativePath": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1024,
      "pattern": "^(?!/)(?![A-Za-z]:[\\\\/])(?!\\\\\\\\)(?!.*(?:^|[\\\\/])\\.\\.(?:[\\\\/]|$)).+$"
    },
    "source": {
      "type": "object",
      "required": [
        "sourceId",
        "repository",
        "commit",
        "license",
        "importedFiles",
        "importedMode",
        "sha256",
        "attributionRequired",
        "fetchedAt"
      ],
      "properties": {
        "sourceId": {
          "type": "string",
          "pattern": "^SRC-[A-Z0-9-]+$"
        },
        "repository": {
          "type": "string",
          "minLength": 9,
          "maxLength": 2048,
          "pattern": "^https://"
        },
        "commit": {
          "type": "string",
          "pattern": "^[0-9a-f]{40}$"
        },
        "license": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "importedFiles": {
          "type": "array",
          "maxItems": 1024,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/portableRelativePath"
          }
        },
        "importedMode": {
          "type": "string",
          "enum": [
            "metadata",
            "adapted",
            "copied"
          ]
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "attributionRequired": {
          "type": "boolean"
        },
        "fetchedAt": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "format": "date-time"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
