{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.dharma-ai.io/repository-knowledge/v1",
  "title": "Locally initialized unsigned repository knowledge catalog",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "managedBy", "organizationId", "repositoryAgentId", "knowledgeBaseId", "initializedAt", "provenance", "repoAtlas", "concepts", "catalogHash"],
  "properties": {
    "schema": { "const": "dharma.repository-knowledge/v1" },
    "managedBy": { "const": "dharma-agent-fabric" },
    "organizationId": { "$ref": "#/$defs/organizationId" },
    "repositoryAgentId": { "$ref": "#/$defs/repositoryAgentId" },
    "knowledgeBaseId": { "type": "string", "pattern": "^repository-kb:sha256:[0-9a-f]{64}$", "description": "Local deterministic identity; runtime verifies its exact organization/repository-agent derivation. Not a server-assigned ID." },
    "initializedAt": { "type": "string", "format": "date-time", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": ["origin", "authority", "serverReleaseId"],
      "properties": {
        "origin": { "const": "locally_initialized" },
        "authority": { "const": "unsigned" },
        "serverReleaseId": { "type": "null" }
      }
    },
    "repoAtlas": {
      "type": "object",
      "additionalProperties": false,
      "required": ["association", "findingsState", "organizationId", "repositoryAgentId"],
      "properties": {
        "association": { "const": "local_scope_only" },
        "findingsState": { "const": "not_observed" },
        "organizationId": { "$ref": "#/$defs/organizationId" },
        "repositoryAgentId": { "$ref": "#/$defs/repositoryAgentId" }
      }
    },
    "concepts": {
      "type": "array",
      "maxItems": 256,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["conceptId", "relativePath", "sha256"],
        "properties": {
          "conceptId": { "type": "string", "pattern": "^concept_[a-z0-9][a-z0-9_-]{0,79}$" },
          "relativePath": {
            "type": "string",
            "maxLength": 500,
            "pattern": "^concepts/(?:[A-Za-z0-9_-]+/)*[A-Za-z0-9_-]+\\.(?:json|md)$",
            "not": { "pattern": "(?:^|/)(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Mm][1-9]|[Ll][Pp][Tt][1-9])(?:\\.|/|$)|(?:^|[/._-])(?:[Ss][Ee][Cc][Rr][Ee][Tt][Ss]?|[Cc][Rr][Ee][Dd][Ee][Nn][Tt][Ii][Aa][Ll][Ss]?|[Pp][Aa][Ss][Ss][Ww][Oo][Rr][Dd][Ss]?|[Pp][Rr][Ii][Vv][Aa][Tt][Ee][-_]?[Kk][Ee][Yy][Ss]?|[Tt][Oo][Kk][Ee][Nn][Ss]?|[Kk][Ee][Yy][Ss][Tt][Oo][Rr][Ee])(?:[/._-]|$)" }
          },
          "sha256": { "$ref": "#/$defs/hash" }
        }
      }
    },
    "catalogHash": { "$ref": "#/$defs/hash", "description": "SHA-256 over canonical sorted-key JSON excluding catalogHash; runtime verifies integrity and cross-field scope. Not a signature." }
  },
  "$defs": {
    "organizationId": { "type": "string", "pattern": "^org_[A-Za-z0-9_]{1,156}$" },
    "repositoryAgentId": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9_-]{0,159}$" },
    "hash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
  }
}
