{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sdd.dev/schemas/sdd-contract.schema.json",
  "title": "SDD Contract",
  "type": "object",
  "required": ["version", "orchestration", "states", "artifacts", "stages"],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "orchestration": {
      "type": "object",
      "required": ["canonical_command", "legacy_aliases"],
      "properties": {
        "canonical_command": {
          "type": "string",
          "minLength": 1
        },
        "legacy_aliases": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "additionalProperties": false
    },
    "states": {
      "type": "object",
      "required": ["orchestration", "artifact", "tui_status"],
      "properties": {
        "orchestration": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "artifact": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "tui_status": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        }
      },
      "additionalProperties": false
    },
    "validations": {
      "type": "object",
      "properties": {
        "diagrams": {
          "type": "object",
          "properties": {
            "allowed_markers": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "additionalProperties": false
        },
        "prompts_agent": {
          "type": "object",
          "properties": {
            "task_id_patterns": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "artifacts": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "required": ["gate", "required_sections", "semantic_validations"],
        "properties": {
          "gate": {
            "type": "boolean"
          },
          "aliases": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "required_sections": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "semantic_validations": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "additionalProperties": false
      }
    },
    "stages": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "key",
          "command",
          "label",
          "order",
          "phase",
          "filename",
          "guided",
          "board_visible",
          "board_lane",
          "requires_human_checkpoint",
          "initial_state",
          "surfaces",
          "traceability_from"
        ],
        "properties": {
          "key": {
            "type": "string",
            "minLength": 1
          },
          "command": {
            "type": "string",
            "minLength": 1
          },
          "label": {
            "type": "string",
            "minLength": 1
          },
          "order": {
            "type": "integer",
            "minimum": 0
          },
          "phase": {
            "type": "string",
            "enum": ["pre", "core", "post"]
          },
          "filename": {
            "type": "string",
            "pattern": "^[0-9]{2}-.+\\.md$"
          },
          "optional": {
            "type": "boolean"
          },
          "guided": {
            "type": "boolean"
          },
          "board_visible": {
            "type": "boolean"
          },
          "board_lane": {
            "type": "string",
            "enum": ["guided", "recorded"]
          },
          "requires_human_checkpoint": {
            "type": "boolean"
          },
          "initial_state": {
            "type": "string",
            "minLength": 1
          },
          "artifact_type": {
            "type": ["string", "null"],
            "minLength": 1
          },
          "aliases": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "surfaces": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "traceability_from": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false
}
