{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aiwg.io/schemas/testing/rule-binding-probes.schema.json",
  "title": "Rule binding behavioral probes",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "rules"
  ],
  "properties": {
    "version": {
      "const": 1
    },
    "extends": {
      "const": "probes.yaml",
      "description": "Overlay the repository's canonical probes.yaml by rule ID."
    },
    "rules": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/definitions/rule"
      }
    }
  },
  "allOf": [
    {
      "if": { "properties": { "extends": {} }, "required": ["extends"] },
      "then": {},
      "else": { "properties": { "rules": { "type": "array", "minItems": 21 } } }
    }
  ],
  "definitions": {
    "assertion": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "path",
            "value"
          ],
          "properties": {
            "type": {
              "const": "json-equals"
            },
            "path": {
              "type": "string",
              "minLength": 1
            },
            "value": {}
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "path",
            "pattern"
          ],
          "properties": {
            "type": {
              "const": "json-matches"
            },
            "path": {
              "type": "string",
              "minLength": 1
            },
            "pattern": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "pattern"
          ],
          "properties": {
            "type": {
              "enum": [
                "tool-matches",
                "tool-not-matches"
              ]
            },
            "body": {
              "const": true,
              "description": "Require authored component content on the successful matching tool result; metadata cards and bound-rule bodies alone do not count. Only valid for tool-matches."
            },
            "pattern": {
              "type": "string",
              "minLength": 1
            }
          },
          "if": { "properties": { "body": {} }, "required": ["body"] },
          "then": { "properties": { "type": { "const": "tool-matches" } } }
        }
      ]
    },
    "probe": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "kind",
        "prompt",
        "assertions"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9-]+$"
        },
        "kind": {
          "enum": [
            "positive",
            "negative"
          ]
        },
        "prompt": {
          "type": "string",
          "minLength": 30
        },
        "governed_action": {
          "enum": ["migration-preview", "migration-preview-v2"],
          "description": "Versioned governed-action contract; v1 is retained for evidence replay and v2 governs prospective exact-argv runs."
        },
        "compound_action": {
          "type": "string",
          "minLength": 1,
          "description": "Read-only action tool pattern; checks are derived from observed discovery JSON."
        },
        "compound_expected": {
          "type": "object", "additionalProperties": false, "required": ["type", "names"],
          "properties": {
            "type": { "enum": ["skill", "agent"] },
            "names": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } }
          }
        },
        "files": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "assertions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/definitions/assertion"
          }
        }
      }
    },
    "rule": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "source",
        "probes"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9-]+$"
        },
        "source": {
          "type": "string",
          "pattern": "^agentic/code/.+\\.md$"
        },
        "probes": {
          "type": "array",
          "minItems": 3,
          "items": {
            "$ref": "#/definitions/probe"
          },
          "allOf": [
            {
              "contains": {
                "type": "object",
                "required": [
                  "kind"
                ],
                "properties": {
                  "kind": {
                    "const": "positive"
                  }
                }
              },
              "minContains": 2
            },
            {
              "contains": {
                "type": "object",
                "required": [
                  "kind"
                ],
                "properties": {
                  "kind": {
                    "const": "negative"
                  }
                }
              }
            }
          ]
        }
      }
    }
  }
}
