{
  "$defs": {
    "FrontMatterCondition": {
      "additionalProperties": false,
      "description": "A front matter key, and optionally a pattern its value must match. Without `matches` the key only has to exist.",
      "patternProperties": {
        "^x-": true
      },
      "properties": {
        "key": {
          "description": "Key name.",
          "minLength": 1,
          "type": "string"
        },
        "matches": {
          "$ref": "rule.schema.json#/$defs/Pcre2Pattern",
          "description": "Pattern for the value; absent means the key only has to exist."
        }
      },
      "required": [
        "key"
      ],
      "type": "object"
    },
    "Matcher": {
      "additionalProperties": false,
      "description": "One condition on a text unit: a PCRE2 pattern, or a list of words and phrases. Matching is case-insensitive unless `case_sensitive` is true.",
      "oneOf": [
        {
          "not": {
            "required": [
              "words"
            ]
          },
          "required": [
            "pattern"
          ]
        },
        {
          "not": {
            "required": [
              "pattern"
            ]
          },
          "required": [
            "words"
          ]
        }
      ],
      "patternProperties": {
        "^x-": true
      },
      "properties": {
        "case_sensitive": {
          "default": false,
          "description": "Match case. Matching ignores case when false.",
          "type": "boolean"
        },
        "pattern": {
          "description": "PCRE2 pattern. Exactly one of `pattern` and `words` is set.",
          "minLength": 1,
          "type": "string"
        },
        "words": {
          "description": "Words and phrases, matched as whole words.",
          "items": {
            "minLength": 1,
            "type": "string"
          },
          "minItems": 1,
          "type": "array",
          "uniqueItems": true
        }
      },
      "type": "object"
    },
    "When": {
      "additionalProperties": false,
      "anyOf": [
        {
          "required": [
            "heading_path"
          ]
        },
        {
          "required": [
            "admonition_title"
          ]
        },
        {
          "required": [
            "front_matter"
          ]
        },
        {
          "required": [
            "path"
          ]
        },
        {
          "required": [
            "sentence"
          ]
        },
        {
          "required": [
            "block_kind"
          ]
        }
      ],
      "description": "Structural conditions. All given conditions must hold. `path` and `front_matter` are document conditions; `heading_path`, `admonition_title` and `block_kind` are block conditions; `sentence` is a sentence condition. Patterns are PCRE2 and case-insensitive. Blocks of kind `code-block` are skipped unless `block_kind` names them.",
      "patternProperties": {
        "^x-": true
      },
      "properties": {
        "admonition_title": {
          "$ref": "rule.schema.json#/$defs/Pcre2Pattern",
          "description": "Matches the title of the enclosing admonition."
        },
        "block_kind": {
          "description": "The block has this kind.",
          "enum": [
            "heading",
            "paragraph",
            "list-item",
            "table-row",
            "code-block",
            "quote"
          ]
        },
        "front_matter": {
          "$ref": "#/$defs/FrontMatterCondition",
          "description": "Front matter key and a pattern for its value."
        },
        "heading_path": {
          "$ref": "rule.schema.json#/$defs/Pcre2Pattern",
          "description": "Matches when the text of any enclosing heading matches."
        },
        "path": {
          "$ref": "rule.schema.json#/$defs/Pcre2Pattern",
          "description": "Matches the file path, with forward slashes."
        },
        "sentence": {
          "$ref": "rule.schema.json#/$defs/Pcre2Pattern",
          "description": "Matches the text of a sentence."
        }
      },
      "type": "object"
    }
  },
  "$id": "https://slopvac.github.io/slopvac/schemas/v3/tagger.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "anyOf": [
    {
      "required": [
        "match"
      ]
    },
    {
      "required": [
        "when"
      ]
    }
  ],
  "dependentRequired": {
    "scope": [
      "when"
    ]
  },
  "dependentSchemas": {
    "when": {
      "not": {
        "anyOf": [
          {
            "required": [
              "match"
            ]
          },
          {
            "required": [
              "unless"
            ]
          },
          {
            "required": [
              "unit"
            ]
          }
        ]
      }
    }
  },
  "description": "A context tagger written as data. It marks text units with a context tag that rules can gate on (rule contexts only and skip). It runs without code and is deterministic. A tag carries a span, a confidence and evidence, like the tags a code tagger returns over the plugin protocol. Semantics are specified in docs/contract/plugins.md. A tagger has either `match` entries, which read the text of one unit, or a `when` object, which reads document structure.",
  "patternProperties": {
    "^x-": true
  },
  "properties": {
    "confidence": {
      "default": 1,
      "description": "Confidence in 0..=1.",
      "maximum": 1,
      "minimum": 0,
      "type": "number"
    },
    "description": {
      "description": "What the tagger does, for people.",
      "minLength": 1,
      "type": "string"
    },
    "evidence": {
      "description": "Short text that explains the tag in reports.",
      "minLength": 1,
      "type": "string"
    },
    "id": {
      "description": "Tagger id, `^[a-z][a-z0-9-]*$`.",
      "pattern": "^[a-z][a-z0-9-]*(?![\\s\\S])",
      "type": "string"
    },
    "match": {
      "description": "The tagger fires when at least one entry matches the unit. Not with `when`.",
      "items": {
        "$ref": "#/$defs/Matcher"
      },
      "minItems": 1,
      "type": "array"
    },
    "schema_version": {
      "$ref": "common.schema.json#/$defs/SchemaVersion",
      "description": "Must be 3."
    },
    "scope": {
      "default": "sentence",
      "description": "How far a matching condition spreads its tag: `sentence` tags each matching sentence, `paragraph` the matching block, `section` the enclosing heading section (up to the next heading of the same or a shallower level) and `document` the whole document.",
      "enum": [
        "sentence",
        "paragraph",
        "section",
        "document"
      ]
    },
    "tag": {
      "$ref": "common.schema.json#/$defs/ContextTag",
      "description": "The context tag the tagger sets."
    },
    "unit": {
      "default": "sentence",
      "description": "The text unit that receives the tag. The span of a tag is the whole unit.",
      "enum": [
        "sentence",
        "paragraph",
        "heading",
        "list-item",
        "table-cell"
      ]
    },
    "unless": {
      "description": "The tagger stays silent for a unit where any of these entries matches. Not with `when`.",
      "items": {
        "$ref": "#/$defs/Matcher"
      },
      "type": "array"
    },
    "when": {
      "$ref": "#/$defs/When",
      "description": "Structural conditions, instead of `match`."
    }
  },
  "required": [
    "schema_version",
    "id",
    "tag"
  ],
  "title": "slopvac v3 declarative tagger",
  "type": "object"
}
