{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://xenostudio.ai/schemas/ownership-policy-v1.json",
  "title": "Xeno ownership policy",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "policyId",
    "policyRevision",
    "canonicalLocation",
    "targetLevel",
    "enforcedLevel",
    "xenoPackagePrefixes",
    "repositories",
    "runtimeComponents",
    "builtinComponents",
    "platformBoundaries",
    "developmentPolicy",
    "cleanRoomProtocol",
    "forbiddenPackages",
    "capabilityGates"
  ],
  "properties": {
    "$schema": { "type": "string" },
    "schemaVersion": { "const": 1 },
    "policyId": { "type": "string", "minLength": 1 },
    "policyRevision": { "type": "integer", "minimum": 1 },
    "canonicalLocation": { "type": "string", "minLength": 1 },
    "mirrorLocations": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "targetLevel": { "enum": ["P1", "P2", "P3", "P4"] },
    "enforcedLevel": { "enum": ["pre-P1", "P1", "P2", "P3", "P4"] },
    "xenoPackagePrefixes": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "repositories": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": ["label", "manifestPaths", "sourceRoots", "reportDirectory"],
        "properties": {
          "label": { "type": "string", "minLength": 1 },
          "manifestPaths": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "minLength": 1 },
            "uniqueItems": true
          },
          "sourceRoots": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "minLength": 1 },
            "uniqueItems": true
          },
          "additionalOwnedSourceRoots": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "minLength": 1 },
            "uniqueItems": true
          },
          "reportDirectory": { "type": "string", "minLength": 1 }
        }
      }
    },
    "runtimeComponents": {
      "type": "array",
      "items": { "$ref": "#/$defs/component" }
    },
    "builtinComponents": {
      "type": "array",
      "items": { "$ref": "#/$defs/component" }
    },
    "platformBoundaries": {
      "type": "array",
      "items": { "$ref": "#/$defs/platformBoundary" }
    },
    "developmentPolicy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["classification"],
      "properties": {
        "classification": { "const": "build-only" }
      }
    },
    "cleanRoomProtocol": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "guide",
        "implementationRecordTemplate",
        "provenanceReviewTemplate",
        "status",
        "counselApprovalRequired"
      ],
      "properties": {
        "guide": { "type": "string", "minLength": 1 },
        "implementationRecordTemplate": { "type": "string", "minLength": 1 },
        "provenanceReviewTemplate": { "type": "string", "minLength": 1 },
        "status": { "enum": ["engineering-draft", "counsel-approved"] },
        "counselApprovalRequired": { "type": "boolean" }
      }
    },
    "testOracles": {
      "type": "array",
      "items": { "$ref": "#/$defs/component" }
    },
    "forbiddenPackages": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "uniqueItems": true
    },
    "capabilityGates": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "requiredFor", "achieved", "evidence"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "requiredFor": { "enum": ["P1", "P2", "P3", "P4"] },
          "achieved": { "type": "boolean" },
          "evidence": { "type": "string", "minLength": 1 }
        }
      }
    }
  },
  "$defs": {
    "classification": {
      "enum": [
        "xeno-owned",
        "platform-api",
        "external-runtime",
        "build-only",
        "test-oracle",
        "temporary-runtime",
        "forbidden"
      ]
    },
    "component": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "classification", "usedBy", "replacement", "expiresAtMilestone"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "classification": { "$ref": "#/$defs/classification" },
        "license": { "type": "string" },
        "usedBy": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "replacement": { "type": "string", "minLength": 1 },
        "expiresAtMilestone": { "type": "string", "minLength": 1 },
        "allowedThrough": { "enum": ["pre-P1", "P1", "P2", "P3"] },
        "artifactPathPrefixes": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        }
      }
    },
    "platformBoundary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "classification", "usedBy", "replacement", "expiresAtMilestone"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "classification": { "$ref": "#/$defs/classification" },
        "usedBy": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1 },
          "uniqueItems": true
        },
        "replacement": { "type": "string", "minLength": 1 },
        "expiresAtMilestone": { "type": "string", "minLength": 1 },
        "allowedThrough": { "enum": ["pre-P1", "P1", "P2", "P3"] }
      }
    }
  }
}
