{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.dharma-ai.io/repository-package/v1",
  "title": "Local Repository Package Manifest",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "organizationId", "workspaceId", "snapshotId", "snapshotHash", "authority", "roots", "files", "skills", "exclusions"],
  "properties": {
    "schema": { "const": "dharma.repository-package/v1" },
    "organizationId": { "$ref": "#/$defs/identity" },
    "workspaceId": { "$ref": "#/$defs/identity" },
    "snapshotId": { "type": "string", "pattern": "^repository-package-[a-f0-9]{64}$" },
    "snapshotHash": { "$ref": "#/$defs/hash" },
    "authority": { "const": "local_inventory_not_signed" },
    "roots": { "const": [".agents/skills", ".claude/skills", ".codex/skills", "skills"] },
    "files": {
      "type": "array", "maxItems": 512,
      "items": {
        "type": "object", "additionalProperties": false,
        "required": ["path", "sha256", "sizeBytes", "role"],
        "properties": {
          "path": { "$ref": "#/$defs/path" }, "sha256": { "$ref": "#/$defs/hash" },
          "managedPath": { "$ref": "#/$defs/managedPath" },
          "sizeBytes": { "type": "integer", "minimum": 0, "maximum": 262144 },
          "role": { "enum": ["skill", "dependency", "approved_output", "knowledge"] }
        }
      }
    },
    "skills": {
      "type": "array", "maxItems": 512,
      "items": {
        "type": "object", "additionalProperties": false,
        "required": ["path", "providerRoot", "entryPath", "contentHash", "availability", "filePaths", "observation"],
        "properties": {
          "path": { "$ref": "#/$defs/path" }, "entryPath": { "$ref": "#/$defs/path" },
          "managedPath": { "$ref": "#/$defs/managedPath" },
          "providerRoot": { "enum": [".agents/skills", ".claude/skills", ".codex/skills", "skills"] },
          "contentHash": { "$ref": "#/$defs/hash" },
          "availability": { "enum": ["available", "partial", "unavailable"] },
          "filePaths": { "type": "array", "maxItems": 512, "uniqueItems": true, "items": { "$ref": "#/$defs/path" } },
          "observation": {
            "type": "object", "additionalProperties": false,
            "required": ["state", "authority", "references"],
            "properties": {
              "state": { "enum": ["not_observed", "reported_observed"] },
              "authority": { "const": "caller_supplied_not_runtime_verified" },
              "references": { "type": "array", "maxItems": 256, "uniqueItems": true, "items": { "$ref": "#/$defs/observation" } }
            },
            "allOf": [
              { "if": { "properties": { "state": { "const": "not_observed" } } }, "then": { "properties": { "references": { "type": "array", "maxItems": 0 } } } },
              { "if": { "properties": { "state": { "const": "reported_observed" } } }, "then": { "properties": { "references": { "type": "array", "minItems": 1 } } } }
            ]
          }
        }
      }
    },
    "knowledge": {
      "type": "object", "additionalProperties": false,
      "required": ["repositoryAgentId", "knowledgeBaseId", "catalogPath", "catalogHash", "authority", "atlasAssociation"],
      "properties": {
        "repositoryAgentId": { "$ref": "#/$defs/identity" },
        "knowledgeBaseId": { "type": "string", "pattern": "^repository-kb:sha256:[a-f0-9]{64}$" },
        "catalogPath": { "const": ".agents/skills/dharma-agent-fabric/knowledge/CATALOG.json" },
        "catalogHash": { "$ref": "#/$defs/hash" },
        "authority": { "const": "locally_initialized_unsigned" },
        "atlasAssociation": { "const": "local_scope_only" }
      }
    },
    "exclusions": {
      "type": "array", "maxItems": 4096,
      "items": {
        "type": "object", "additionalProperties": false, "required": ["path", "reason"],
        "properties": {
          "path": { "$ref": "#/$defs/path" },
          "reason": { "enum": ["unsupported_path", "excluded_path", "symlink", "not_regular_file", "unavailable", "missing_dependency", "binary_content", "secret_content", "local_path_content", "invalid_dependency", "generated_dependency"] }
        }
      }
    }
  },
  "$defs": {
    "identity": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$" },
    "hash": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" },
    "managedPath": { "type": "string", "minLength": 15, "maxLength": 500, "pattern": "^skills/source/(?!.*(?:^|/)[.]{1,2}(?:/|$))[A-Za-z0-9._ -]+(?:/[A-Za-z0-9._ -]+)*$" },
    "path": { "type": "string", "minLength": 1, "maxLength": 500, "pattern": "^(?!.*(?:^|/)[.]{1,2}(?:/|$))[A-Za-z0-9._ -]+(?:/[A-Za-z0-9._ -]+)*$" },
    "observation": {
      "type": "object", "additionalProperties": false,
      "required": ["skillPath", "skillHash", "sourcePath", "sourceHash"],
      "properties": {
        "skillPath": { "$ref": "#/$defs/path" }, "skillHash": { "$ref": "#/$defs/hash" },
        "sourcePath": { "$ref": "#/$defs/path" }, "sourceHash": { "$ref": "#/$defs/hash" }
      }
    }
  }
}
