{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/noemauser/OpenFeed/raw/main/schemas/knowledge-pack-v0.1.json",
  "title": "OpenFeed Knowledge Pack",
  "description": "Atomic unit of feedable knowledge for AI agents (OpenFeed v0.1).",
  "type": "object",
  "required": ["id", "version", "title", "summary", "content", "provenance", "quality", "license"],
  "additionalProperties": false,
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique identifier (e.g. kp_…)",
      "minLength": 1
    },
    "version": {
      "type": "string",
      "description": "Semantic version of this pack instance",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "summary": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1000
    },
    "content": {
      "type": "object",
      "required": ["type", "body"],
      "additionalProperties": false,
      "properties": {
        "type": {
          "type": "string",
          "enum": ["markdown", "json", "text", "structured"]
        },
        "body": {
          "description": "The actual knowledge payload"
        },
        "format": {
          "type": "string",
          "description": "Optional sub-format (e.g. markdown, jsonl)"
        }
      }
    },
    "provenance": {
      "type": "object",
      "required": ["created_by", "created_at", "method"],
      "additionalProperties": false,
      "properties": {
        "created_by": {
          "type": "string",
          "description": "agent_id, human_id, DID, or project persona"
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "sources": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": { "type": "string" },
              "title": { "type": "string" },
              "accessed_at": { "type": "string", "format": "date-time" },
              "license": { "type": "string" }
            }
          }
        },
        "method": {
          "type": "string",
          "description": "extracted | synthesized | human-authored | multi-agent-debate | ..."
        },
        "parent_packs": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "quality": {
      "type": "object",
      "required": ["self_score", "confidence"],
      "additionalProperties": false,
      "properties": {
        "self_score": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "community_score": {
          "type": ["number", "null"],
          "minimum": 0,
          "maximum": 1
        },
        "reproduction_status": {
          "type": "string",
          "enum": ["untested", "reproduced", "failed", "partial"]
        },
        "safety_flags": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "relations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["type", "target"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["derived_from", "improves", "contradicts", "supersedes", "tests", "related"]
          },
          "target": { "type": "string" }
        }
      }
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" }
    },
    "license": {
      "type": "string",
      "description": "SPDX or simple license string (MIT, CC-BY-4.0, ...)"
    },
    "signatures": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "alg": { "type": "string" },
          "key_id": { "type": "string" },
          "sig": { "type": "string" }
        }
      }
    }
  }
}
