{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ECC Workflow Definition",
  "type": "object",
  "properties": {
    "version": {
      "type": "string",
      "minLength": 1
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string",
      "minLength": 1
    },
    "provider": {
      "type": "string",
      "minLength": 1
    },
    "model": {
      "type": "string",
      "minLength": 1
    },
    "interactive": {
      "type": "boolean"
    },
    "additionalDirectories": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "nodes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "depends_on": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          },
          "prompt": {
            "type": "string",
            "minLength": 1
          },
          "bash": {
            "type": "string",
            "minLength": 1
          },
          "timeout_ms": {
            "type": "integer",
            "minimum": 1
          },
          "command": {
            "type": "string",
            "minLength": 1
          },
          "interactive": {
            "type": "boolean"
          },
          "loop": {
            "type": "object",
            "properties": {
              "prompt": {
                "type": "string",
                "minLength": 1
              },
              "until": {
                "type": "string",
                "minLength": 1
              },
              "fresh_context": {
                "type": "boolean"
              },
              "interactive": {
                "type": "boolean"
              }
            },
            "required": [
              "prompt",
              "until"
            ],
            "additionalProperties": false
          }
        },
        "oneOf": [
          {
            "required": [
              "prompt"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "bash"
                  ]
                },
                {
                  "required": [
                    "command"
                  ]
                },
                {
                  "required": [
                    "loop"
                  ]
                }
              ]
            }
          },
          {
            "required": [
              "bash"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "prompt"
                  ]
                },
                {
                  "required": [
                    "command"
                  ]
                },
                {
                  "required": [
                    "loop"
                  ]
                }
              ]
            }
          },
          {
            "required": [
              "command"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "prompt"
                  ]
                },
                {
                  "required": [
                    "bash"
                  ]
                },
                {
                  "required": [
                    "loop"
                  ]
                }
              ]
            }
          },
          {
            "required": [
              "loop"
            ],
            "not": {
              "anyOf": [
                {
                  "required": [
                    "prompt"
                  ]
                },
                {
                  "required": [
                    "bash"
                  ]
                },
                {
                  "required": [
                    "command"
                  ]
                }
              ]
            }
          }
        ],
        "required": [
          "id"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "version",
    "name",
    "description",
    "nodes"
  ],
  "additionalProperties": false
}
