{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/alphazede/bearing-lite/schemas/implementation.schema.json",
  "title": "Bearing Lite implementation.json",
  "description": "Nested execution authority. XLSX is never authority. Owner-configured n, k, and c have no assistant default integers. Every slice requires CONTRACT-EMV-008 fields including reasoning_level (object), not a sibling reasoning string. human_decision may be a string, object, or null. authority_id is a nonempty string on dispatchable slices and may be null only when dispatchable is false or slice_status is publication-blocked. Extra lifecycle metadata is allowed. lineup_freeze is not a live field; profile_freeze is required.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "schema_version",
    "artifact",
    "source_baseline",
    "journey_settings",
    "profile_freeze",
    "waves",
    "dependencies",
    "slices",
    "traceability"
  ],
  "$defs": {
    "contentfulObject": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": true
    },
    "stringList": {
      "type": "array",
      "items": { "type": "string" }
    },
    "slice": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "role",
        "goal",
        "type",
        "requirement_ids",
        "design_ids",
        "seit_proof_rows",
        "design_lenses",
        "model_route",
        "reasoning_level",
        "review_path",
        "write_set",
        "command_ids",
        "stop_condition",
        "human_decision",
        "authority_id"
      ],
      "properties": {
        "id": { "type": "string" },
        "role": { "type": "string", "minLength": 1 },
        "goal": { "type": "string", "minLength": 1, "maxLength": 512 },
        "type": { "type": "string", "minLength": 1 },
        "requirement_ids": { "$ref": "#/$defs/stringList" },
        "design_ids": { "$ref": "#/$defs/stringList" },
        "seit_proof_rows": { "$ref": "#/$defs/stringList" },
        "design_lenses": { "$ref": "#/$defs/stringList" },
        "model_route": { "$ref": "#/$defs/contentfulObject" },
        "reasoning_level": { "$ref": "#/$defs/contentfulObject" },
        "review_path": { "$ref": "#/$defs/contentfulObject" },
        "write_set": { "$ref": "#/$defs/stringList" },
        "command_ids": { "$ref": "#/$defs/stringList" },
        "stop_condition": { "type": "string", "minLength": 1 },
        "human_decision": { "type": ["string", "object", "null"] },
        "authority_id": { "type": ["string", "null"] },
        "dispatchable": { "type": "boolean" },
        "slice_status": { "type": "string" },
        "work_class": {
          "type": "string",
          "enum": ["light", "judgement"],
          "description": "light: inputs fully determine the output and the packet's command verifies it (skills/light-implementer). Default judgement."
        },
        "work_class_reason": { "type": "string", "minLength": 1 }
      },
      "allOf": [
        {
          "if": {
            "not": {
              "anyOf": [
                {
                  "properties": { "dispatchable": { "const": false } },
                  "required": ["dispatchable"]
                },
                {
                  "properties": { "slice_status": { "const": "publication-blocked" } },
                  "required": ["slice_status"]
                }
              ]
            }
          },
          "then": {
            "properties": {
              "authority_id": { "type": "string", "minLength": 1 }
            }
          }
        },
        {
          "if": {
            "properties": { "work_class": { "const": "light" } },
            "required": ["work_class"]
          },
          "then": {
            "required": ["work_class_reason"],
            "properties": {
              "role": { "const": "Light Implementer" },
              "command_ids": { "minItems": 1 }
            }
          }
        }
      ]
    },
    "dodNa": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "not_applicable": { "type": "boolean" },
        "na": { "type": "boolean" },
        "reason": { "type": "string", "minLength": 1 },
        "status": { "type": "string" }
      }
    },
    "dodView": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "format": { "type": "string", "enum": ["svg", "png"] },
        "path": { "type": "string", "minLength": 1 },
        "inline": { "type": "string", "minLength": 1 },
        "alt": { "type": "string" }
      }
    },
    "dodModel": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "mode": { "type": "string" },
        "source": { "type": "string" },
        "revision": { "type": "string" },
        "digest": { "type": "string" },
        "viewpoint": { "type": "string" },
        "trace": { "type": "string" },
        "limitations": { "type": "string" },
        "render_status": { "type": "string" },
        "required": { "type": "boolean" },
        "selected": { "type": "boolean" },
        "not_applicable": { "type": "boolean" },
        "reason": { "type": "string" },
        "view": { "$ref": "#/$defs/dodView" },
        "views": {
          "type": "array",
          "items": { "$ref": "#/$defs/dodView" }
        }
      }
    },
    "dodManifest": {
      "type": "object",
      "additionalProperties": true,
      "description": "Structured rendering input for the versioned DoD Manifest template. Planning fields are the immutable projection; closeout is append-only. Activated models (selected OR required, including render_status READY/MISSING/STALE) must bind digest plus view.format svg|png and view.path or svg view.inline, either on the planning row or via closeout.model_views. The renderer never invents views or evidence and never rewrites planning model rows.",
      "required": ["template_version", "output_name", "title"],
      "properties": {
        "template_version": { "type": "string", "const": "1.0.1" },
        "output_name": { "type": "string", "minLength": 1, "pattern": "^[A-Za-z0-9._-]+-dod-manifest\\.html$" },
        "state": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "lede": { "type": "string" },
        "bluf": { "type": "string" },
        "identity": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": true,
            "properties": {
              "label": { "type": "string" },
              "value": { "type": ["string", "number"] }
            }
          }
        },
        "outcome": { "type": "string" },
        "scope": { "type": "array", "items": { "type": "string" } },
        "exclusions": { "type": "array", "items": { "type": "string" } },
        "definition_of_done": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "requirements": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "architecture": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "models": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "$ref": "#/$defs/dodModel" } }
          ]
        },
        "lineup": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "tasks": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "vv": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "documentation": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "risks": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "authority": {
          "oneOf": [
            { "$ref": "#/$defs/dodNa" },
            { "type": "array", "items": { "type": "object", "additionalProperties": true } }
          ]
        },
        "closeout": {
          "type": "object",
          "additionalProperties": true,
          "description": "Append-only actuals. Must not rewrite planning projection fields.",
          "properties": {
            "candidate": { "type": ["string", "null"] },
            "changed_paths": { "type": "array" },
            "evidence": { "type": "array" },
            "open_gaps": { "type": "array" },
            "owner_acceptance": { "type": ["string", "null"] },
            "slice_receipts": { "type": "array" },
            "amendments": { "type": "array" },
            "owner_amendments": { "type": "array" },
            "documentation_completion": true,
            "anomalies": true,
            "repairs": true,
            "recovery_used": true,
            "residual_gaps": { "type": "array" },
            "completion_status": { "type": "string" },
            "model_views": {
              "type": "array",
              "description": "Append-only supplemental rendering bindings keyed by planning model_id. Each entry may carry digest and view only. Duplicate, unknown, semantically overriding, or already-planned bindings are rejected.",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["model_id", "digest", "view"],
                "properties": {
                  "model_id": { "type": "string", "minLength": 1 },
                  "digest": { "type": "string", "minLength": 1 },
                  "view": { "$ref": "#/$defs/dodView" }
                }
              }
            }
          }
        }
      }
    }
  },
  "properties": {
    "schema_version": { "type": "string", "minLength": 1 },
    "artifact": { "$ref": "#/$defs/contentfulObject" },
    "source_baseline": { "$ref": "#/$defs/contentfulObject" },
    "journey_settings": {
      "type": "object",
      "additionalProperties": true,
      "required": ["review_cardinality"],
      "properties": {
        "review_cardinality": {
          "type": "object",
          "additionalProperties": true,
          "description": "Owner-configured reviewer count n, repair bound k, and confirmation count c. No default integers.",
          "required": ["n", "k", "c"],
          "properties": {
            "n": { "type": "integer", "minimum": 0 },
            "k": { "type": "integer", "minimum": 0 },
            "c": { "type": "integer", "minimum": 0 }
          }
        },
        "development_strategy": {
          "type": "object",
          "additionalProperties": true,
          "required": ["mode"],
          "properties": {
            "mode": { "type": "string", "enum": ["single_implementer", "tdd"] }
          }
        },
        "assurance_cadence": {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "test_engineer": {
              "type": "object",
              "additionalProperties": true,
              "properties": {
                "assurance": { "type": "string", "enum": ["slice", "phase", "lifecycle"] }
              }
            },
            "reviewer": { "type": "string", "enum": ["slice", "phase", "lifecycle"] },
            "integration_engineer": {
              "type": "object",
              "additionalProperties": true,
              "properties": {
                "execution": { "type": "string", "enum": ["slice", "phase", "lifecycle"] }
              }
            }
          }
        },
        "planning_to_implementation_clean_session": { "type": "boolean" }
      }
    },
    "profile_freeze": { "$ref": "#/$defs/contentfulObject" },
    "waves": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "dependencies": {
      "type": "array",
      "items": { "type": "object", "additionalProperties": true }
    },
    "slices": {
      "type": "array",
      "items": { "$ref": "#/$defs/slice" }
    },
    "traceability": { "$ref": "#/$defs/contentfulObject" },
    "dod_manifest": { "$ref": "#/$defs/dodManifest" }
  }
}
