{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "daggry/project@1",
  "title": "daggry/project@1: the project config",
  "type": "object",
  "required": [
    "format"
  ],
  "additionalProperties": false,
  "patternProperties": {
    "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
  },
  "properties": {
    "format": {
      "const": "daggry/project@1"
    },
    "project": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "name": {
          "$ref": "#/$defs/name"
        },
        "tools": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/label"
          }
        },
        "setup": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/command"
          }
        },
        "entry_points": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/path"
          }
        }
      }
    },
    "areas": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-z][a-z0-9_-]*$": {
          "$ref": "#/$defs/area"
        },
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      }
    },
    "validators": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-z][a-z0-9_-]*$": {
          "$ref": "#/$defs/validator"
        },
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "canonical": {
          "$ref": "#/$defs/validatorName"
        },
        "also": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/validatorName"
          },
          "uniqueItems": true
        },
        "thresholds": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "patternProperties": {
              "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
            },
            "properties": {
              "validator": {
                "$ref": "#/$defs/validatorName"
              },
              "read": {
                "type": "string",
                "pattern": "^(exit_code|findings|findings\\.(pass|fail|error|skip)|metrics\\.[a-z][a-z0-9_]*)$"
              },
              "min": {
                "type": "number"
              },
              "max": {
                "type": "number"
              }
            },
            "required": [
              "validator",
              "read"
            ],
            "anyOf": [
              {
                "required": [
                  "min"
                ]
              },
              {
                "required": [
                  "max"
                ]
              }
            ]
          }
        }
      },
      "required": [
        "canonical"
      ]
    },
    "protect": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "paths": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/pathEntry"
          }
        }
      }
    }
  },
  "$defs": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "label": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
    },
    "validatorName": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]*$"
    },
    "path": {
      "type": "string",
      "pattern": "^(?!/)(?!.*(^|/)\\.\\.(/|$))\\S+$"
    },
    "pathEntry": {
      "type": "string",
      "minLength": 1,
      "anyOf": [
        {
          "pattern": "^area:[a-z][a-z0-9_-]*$"
        },
        {
          "not": {
            "pattern": "^area:"
          }
        }
      ]
    },
    "area": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "paths": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "role": {
          "$ref": "#/$defs/label"
        },
        "description": {
          "$ref": "#/$defs/name"
        }
      },
      "required": [
        "paths"
      ]
    },
    "command": {
      "anyOf": [
        {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        {
          "$ref": "#/$defs/path"
        }
      ]
    },
    "validator": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "run": {
          "$ref": "#/$defs/command"
        },
        "kind": {
          "$ref": "#/$defs/label"
        },
        "result": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
          },
          "properties": {
            "contract": {
              "anyOf": [
                {
                  "enum": [
                    "exit-code",
                    "document"
                  ]
                },
                {
                  "type": "string",
                  "pattern": "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$"
                }
              ]
            },
            "path": {
              "$ref": "#/$defs/path"
            }
          },
          "required": [
            "contract"
          ]
        },
        "timeout": {
          "type": "integer",
          "minimum": 1
        },
        "env": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
          }
        },
        "needs": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
          },
          "properties": {
            "tools": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/label"
              }
            },
            "runner": {
              "$ref": "#/$defs/name"
            }
          }
        },
        "expose": {
          "enum": [
            "factory",
            "agent"
          ]
        }
      },
      "required": [
        "run",
        "kind"
      ]
    }
  }
}
