{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengdd.org/schema/core/v0.8/opengdd-build.schema.json",
  "title": "OpenGDD v0.7 build manifest",
  "type": "object",
  "required": ["opengdd", "spec", "designer", "builder", "personalization", "resolved_tuning", "evidence"],
  "additionalProperties": false,
  "properties": {
    "opengdd": { "const": "0.8" },
    "spec": {
      "type": "object",
      "required": ["id", "version"],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
        },
        "version": { "$ref": "#/$defs/specVersion" }
      }
    },
    "designer": { "$ref": "#/$defs/party" },
    "builder": { "$ref": "#/$defs/party" },
    "personalization": {
      "type": "object",
      "required": ["answers"],
      "additionalProperties": false,
      "properties": {
        "answers": {
          "type": "object",
          "additionalProperties": {
            "type": ["string", "number"]
          },
          "description": "Question id to answer used, incl. defaulted questions; choice/text answers are strings, number answers numbers; empty object when none. Cross-checks against declared questions are validator-level (SPEC 7)."
        }
      }
    },
    "resolved_tuning": {
      "type": "object",
      "required": ["values"],
      "additionalProperties": false,
      "properties": {
        "values": {
          "type": "object",
          "additionalProperties": { "type": "number" },
          "description": "Complete flat values map after personalization answers are applied, including package values and filled contract values (SPEC 5 resolved tuning snapshot)"
        }
      }
    },
    "evidence": {
      "type": "object",
      "required": ["result_hash", "payload", "acceptance"],
      "additionalProperties": true,
      "properties": {
        "result_hash": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "payload": {
          "type": "object",
          "required": ["covers", "file"],
          "additionalProperties": false,
          "properties": {
            "covers": {
              "type": "string",
              "minLength": 1,
              "description": "States in plain words which artifacts the hash covers"
            },
            "file": {
              "$ref": "#/$defs/packagePath",
              "description": "Package-relative path to the canonical payload bytes"
            }
          }
        },
        "acceptance": {
          "type": "object",
          "required": ["passed", "total"],
          "additionalProperties": false,
          "properties": {
            "passed": { "type": "integer", "minimum": 0 },
            "total": { "type": "integer", "minimum": 0 },
            "sampled": {
              "type": "array",
              "uniqueItems": true,
              "items": { "type": "string", "pattern": "^AT-[1-9][0-9]*$" },
              "description": "General tests whose scopes were sampled rather than checked whole; absent or empty means every general test was checked whole."
            }
          }
        },
        "runner": {
          "type": "object",
          "required": ["id", "version"],
          "additionalProperties": false,
          "properties": {
            "id": { "type": "string", "minLength": 1 },
            "version": { "type": "string", "minLength": 1 }
          },
          "description": "Identity of the runner profile that interpreted runtime acceptance-test semantics. Source-backed validation requires it when the package carries a runtime test."
        },
        "contracts": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["adoption", "pack"],
            "additionalProperties": false,
            "properties": {
              "adoption": { "type": "string", "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$" },
              "pack": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
            }
          },
          "description": "One matching content hash for every checked contract adoption; absent when the package has none."
        }
      },
      "$comment": "additionalProperties true by design: build-local checkpoint records, replays, and transcripts live here without being part of the core-defined shape (SPEC 7). runner is the standardized identity metadata within that open evidence envelope."
    },
    "commerce": {
      "type": "object",
      "required": ["license", "split"],
      "additionalProperties": false,
      "properties": {
        "license": { "enum": ["opengdd-share-v0"] },
        "split": {
          "type": "object",
          "required": ["designer", "builder"],
          "additionalProperties": false,
          "properties": {
            "designer": { "type": "number", "minimum": 0, "maximum": 100 },
            "builder": { "type": "number", "minimum": 0, "maximum": 100 }
          },
          "description": "Percentages; validator must additionally check they sum to 100"
        },
        "derived_from": {
          "type": "object",
          "required": ["id", "version"],
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
            },
            "version": { "$ref": "#/$defs/specVersion" }
          }
        }
      },
      "description": "The manifest's commerce profile, copied verbatim; present only when a commerce split exists to attribute"
    }
  },
  "$defs": {
    "specVersion": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$",
      "description": "Design-spec version: numeric MAJOR.MINOR.PATCH with no leading zero except 0 and no prerelease or build suffix"
    },
    "packagePath": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?![/\\\\])(?![A-Za-z][A-Za-z0-9+.-]*:)[^\\\\]+$",
      "description": "Forward-slash package-relative path; normalization containment is validator-level"
    },
    "party": {
      "type": "object",
      "required": ["name"],
      "additionalProperties": false,
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "handle": { "type": "string" },
        "contact": { "type": "string" },
        "role": { "type": "string" }
      }
    }
  }
}
