{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://opengdd.org/schema/core/v0.6/opengdd-build.schema.json",
  "title": "OpenGDD v0.6 build manifest",
  "type": "object",
  "required": ["opengdd", "spec", "designer", "builder", "personalization", "resolved_tuning", "evidence"],
  "additionalProperties": false,
  "properties": {
    "opengdd": { "const": "0.6" },
    "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": ["tunables", "constants"],
      "additionalProperties": false,
      "properties": {
        "tunables": {
          "type": "object",
          "additionalProperties": { "type": "number" },
          "description": "Complete flat tunables map after answer resolution (SPEC 5 resolved tuning snapshot)"
        },
        "constants": {
          "type": "object",
          "additionalProperties": { "type": "number" },
          "description": "Complete package and live contract constants map; empty only when neither source declares a constant"
        }
      }
    },
    "evidence": {
      "type": "object",
      "required": ["algorithm", "result_hash", "payload", "acceptance"],
      "additionalProperties": true,
      "properties": {
        "algorithm": {
          "enum": ["sha256"],
          "description": "The only currently defined algorithm"
        },
        "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 }
          }
        },
        "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."
        },
        "direction_observations": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "object",
            "required": ["claim", "context"],
            "additionalProperties": false,
            "properties": {
              "claim": {
                "type": "string",
                "pattern": "^constraints\\.(colors|thresholds|timing)\\.[a-z0-9]+(-[a-z0-9]+)*$"
              },
              "context": { "type": "string", "minLength": 1 }
            }
          },
          "description": "One observation record per declared direction constraint. The claim path and uniqueness/completeness are source-backed validator checks; context names what was actually observed without standardizing an engine."
        }
      },
      "$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 and direction_observations are the standardized identity and direction-observation 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"
    },
    "renderer": {
      "type": "string",
      "minLength": 1,
      "description": "Optional free-text declaration of the rendering technique this build used, such as \"three.js 0.185.1, WebGL\" (SPEC 7). The renderer is the builder's fact, never the spec's: SPEC 3's platform names the state space, and two builds of one spec may declare different renderers. Declarative only in v0.6; the web-1 capture recipe does not read it."
    },
    "capture_profile": {
      "type": "object",
      "required": ["id", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "minLength": 1, "description": "Build-local label for the concrete adapter invocation" },
        "type": { "enum": ["web-1"], "description": "Closed, versioned enum. web-1 names the headless-browser reference profile summarized in SPEC 7: synthetic-clock deterministic frame capture with a capture-manifest record. Widening this enum is an ordinary additive change." }
      },
      "$comment": "type selects the capture recipe on its own. The optional build-level renderer string (SPEC 7) is informative and is never read for recipe selection, so the two never need reconciling.",
      "description": "Optional declaration of which capture adapter and serving/run recipe produced this certification (SPEC 7). Declarative only: does not change acceptance-count or hash-payload rules."
    },
    "resources": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/buildResource" },
      "$comment": "Resource-id uniqueness is a validator-level check. List presence is a disclosure, not a certified-complete claim (SPEC 7).",
      "description": "Optional build-resource provenance disclosure list: kits, third-party assets, and tools the build consumed (SPEC 7). Provenance only: it creates no split obligation and changes no certification outcome."
    },
    "direction_result": { "$ref": "#/$defs/directionResult" }
  },
  "$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" }
      }
    },
    "buildResource": {
      "type": "object",
      "required": ["id", "type", "artifact", "license", "hash"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "type": { "enum": ["kit", "asset", "tool"] },
        "artifact": {
          "type": "string",
          "minLength": 1,
        "description": "Names the exact single immutable file or archive hash covers: a URL, a registry coordinate (name@version), or a package-relative path. A multi-file kit, tree, or tool install MUST be packaged into one archive before hashing; v0.6 defines no directory/tree-hash canonicalization."
        },
        "license": { "type": "string", "minLength": 1, "description": "Free-text declaration; presence, not truth, is checked" },
        "hash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$", "description": "Covers exactly the bytes named by artifact" },
        "source": { "type": "string", "description": "Optional origin (URL, registry id, or similar), distinct from artifact's exact-bytes identification" }
      }
    },
    "directionClaimPath": {
      "type": "string",
      "pattern": "^(pillars|mood|anti|must_keep)\\.[a-z0-9]+(-[a-z0-9]+)*$",
      "$comment": "This pattern is a necessary, not sufficient, check. A validator-level cross-check (SPEC 7/9.10) additionally MUST resolve every path against the certifying spec's direction.json and reject a path that does not name a declared entry of one of the four fixed-judged kinds (pillars.*, mood.*, anti.*, must_keep.*). A syntactically well-formed but nonexistent path, such as pillars.not-declared, is a hard failure.",
      "description": "SPEC 9.10 dotted-path citation of a judged direction claim"
    },
    "directionResult": {
      "type": "object",
      "additionalProperties": false,
      "required": ["judged"],
      "properties": {
        "judged": {
          "type": "object",
          "required": ["status", "assessed", "adherent"],
          "additionalProperties": false,
          "properties": {
            "status": {
              "const": "pending",
            "description": "SPEC 9.10 judged gate. pending is the only value v0.6 defines because the panel protocol is not yet integrated into the conformance suite."
            },
            "assessed": {
              "type": "array",
              "uniqueItems": true,
              "items": { "$ref": "#/$defs/directionClaimPath" },
          "description": "Every judged claim this run attempted to assess (coverage-of-claims-assessed, SPEC 9.10). Each path MUST resolve to a declared entry; see directionClaimPath $comment."
            },
            "adherent": {
              "type": "array",
              "uniqueItems": true,
              "items": { "$ref": "#/$defs/directionClaimPath" },
          "description": "The subset of assessed judged as adherent (adherence-over-assessed-claims, SPEC 9.10). A validator-level check requires adherent to be a subset of assessed and requires every path to resolve to a declared entry."
            }
          },
      "description": "Required exactly when the certifying spec's direction.json declares at least one judged claim (pillars/mood/anti/must_keep); absent otherwise."
        }
      },
      "description": "SPEC 9.10 direction certification result. Required exactly when the certifying spec's direction.json declares at least one judged claim; absent otherwise."
    }
  }
}
