{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://muthu4all.github.io/compile-once-enterprise/spec/schemas/capsule-manifest.schema.json",
  "title": "Compile-Once Capsule Manifest",
  "description": "The document that ships with every capsule: what it does, what it may read, how it was proven, who owns it and how it runs. Draft v0.1.",
  "type": "object",
  "required": ["spec", "capsule", "version", "kind", "sphere", "contract", "request", "inputs", "outputs", "tests", "owner", "build", "runtime"],
  "properties": {
    "spec": { "const": "compile-once/capsule-manifest/v0.1" },
    "capsule": { "type": "string", "pattern": "^[a-z][a-z0-9-]{1,60}$" },
    "version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
    "kind": { "enum": ["query", "search", "rules", "calculate", "match", "score", "extract", "monitor", "route", "recommend"] },
    "sphere": { "type": "string", "description": "The one sphere this capsule may read." },
    "contract": { "type": "string", "description": "Sphere contract version the capsule was built and tested against, e.g. claims.v9." },
    "request": { "type": "string", "description": "The plain-language request the capsule answers." },
    "inputs": { "type": "object", "additionalProperties": { "type": "object", "required": ["type"], "properties": { "type": { "type": "string" }, "default": {}, "description": { "type": "string" } } } },
    "outputs": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
    "access": { "enum": ["read-only", "read-write"], "default": "read-only" },
    "tests": {
      "type": "object", "required": ["passed", "total", "suites"],
      "properties": {
        "passed": { "type": "integer", "minimum": 0 },
        "total": { "type": "integer", "minimum": 1 },
        "suites": { "type": "array", "items": { "enum": ["golden", "edge", "permission", "performance", "regression"] } }
      }
    },
    "owner": { "type": "object", "required": ["team", "approver"], "properties": { "team": { "type": "string" }, "approver": { "type": "string" }, "approved_at": { "type": "string", "format": "date-time" } } },
    "build": {
      "type": "object", "required": ["by"],
      "properties": {
        "by": { "const": "forge" },
        "model_use": { "const": "build-time-only" },
        "source_ref": { "type": "string", "description": "Commit or artefact reference of the generated code." }
      }
    },
    "runtime": {
      "type": "object", "required": ["llm_calls"],
      "properties": {
        "llm_calls": { "const": "none", "description": "Routine runs never call a large language model." },
        "local_model": { "type": ["object", "null"], "description": "Declared small local model (e.g. OCR), if any.", "properties": { "name": { "type": "string" }, "version": { "type": "string" }, "purpose": { "type": "string" } } },
        "p95_latency_ms": { "type": "number" },
        "deploy_targets": { "type": "array", "items": { "enum": ["cloud", "on-premises", "edge", "offline"] } }
      }
    },
    "rollback": { "type": "object", "properties": { "previous_version": { "type": ["string", "null"] }, "retain_days": { "type": "integer" } } },
    "status": { "enum": ["draft", "approved", "published", "deprecated", "retired"], "default": "published" }
  },
  "additionalProperties": false
}
