{
  "$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
      }
    },
    "personas": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[a-z][a-z0-9_-]*$": {
          "$ref": "#/$defs/persona"
        },
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      }
    },
    "validators": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true,
        "^(?!(project|daggry|coverage|no_regression|baseline_proof)$)[a-z][a-z0-9_-]*$": {
          "$ref": "#/$defs/validator"
        }
      }
    },
    "judges": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true,
        "^(?!(project|daggry|coverage|no_regression|baseline_proof)$)[a-z][a-z0-9_-]*$": {
          "$ref": "#/$defs/judge"
        }
      }
    },
    "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": "^(?!(project|daggry|coverage|no_regression|baseline_proof)$)[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": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      },
      "description": "A program and its arguments. The first string is the program. No shell reads the list."
    },
    "validator": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "run": {
          "$ref": "#/$defs/command",
          "description": "What runs. Required: a validator exists only as a declared entry."
        },
        "role": {
          "$ref": "#/$defs/label",
          "default": "custom"
        },
        "output": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_-]*$",
          "default": "exit-code",
          "description": "How Daggry reads the output: exit-code (default), document, or the name of a tool format such as junit or sarif."
        },
        "output_file": {
          "$ref": "#/$defs/path",
          "description": "The file the validator writes its output to. Absent: standard output."
        },
        "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"
      ]
    },
    "judge": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "run": {
          "$ref": "#/$defs/command",
          "description": "A custom judge: what runs. Daggry writes the evidence trail as JSON on standard input ({\"records\": [...]}) and reads a verdict body from standard output."
        },
        "timeout": {
          "type": "integer",
          "minimum": 1
        },
        "criterion": {
          "type": "string",
          "minLength": 1,
          "description": "A rubric judge: a fixed criterion id of the plan. Absent: the current criterion of the enclosing loop over the plan's criteria."
        },
        "rubric": {
          "$ref": "#/$defs/path",
          "description": "A rubric judge: the rubric file. A person approves it and Daggry pins its digest."
        },
        "engine": {
          "type": "string",
          "minLength": 1,
          "description": "A rubric judge: the name of an engine the tenant config declares."
        }
      },
      "oneOf": [
        {
          "required": [
            "run"
          ]
        },
        {
          "required": [
            "rubric",
            "engine"
          ]
        }
      ]
    },
    "persona": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^[A-Za-z0-9_-]+/[A-Za-z0-9_-]+$": true
      },
      "properties": {
        "description": {
          "$ref": "#/$defs/name",
          "description": "One or two sentences that say what the persona is for."
        },
        "engine": {
          "$ref": "#/$defs/name",
          "description": "The name of an engine in agents.engines of the tenant config."
        },
        "instructions": {
          "type": "object",
          "additionalProperties": false,
          "minProperties": 1,
          "maxProperties": 1,
          "properties": {
            "text": {
              "type": "string",
              "minLength": 1,
              "description": "The instructions, inline."
            },
            "path": {
              "$ref": "#/$defs/path",
              "description": "The instruction file, relative to the workspace root and read from the baseline."
            }
          },
          "description": "The persona's instructions: exactly one of text and path."
        },
        "transcript": {
          "$ref": "#/$defs/path",
          "description": "For a persona on the replay engine: the recorded transcript it plays back, in place of instructions."
        }
      },
      "required": [
        "engine"
      ],
      "oneOf": [
        {
          "required": [
            "instructions"
          ]
        },
        {
          "required": [
            "transcript"
          ]
        }
      ]
    }
  }
}
