{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mathgraph.org/schemas/discover-request-v1.schema.json",
  "title": "MathGraph Discover request v1",
  "description": "Local advisory contract. Duplicate JSON keys and nonfinite numbers are forbidden. IDs must be unique and source references must resolve. No verification, terminal outcome, or hosted service is implied.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "request_id",
    "policy",
    "top_k",
    "candidates",
    "sources",
    "source_diagnostics",
    "reported_metrics"
  ],
  "properties": {
    "schema_version": {
      "const": "mathgraph.discover-request.v1"
    },
    "request_id": {
      "type": "string",
      "minLength": 1,
      "pattern": "\\S"
    },
    "policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "beta"
      ],
      "properties": {
        "mode": {
          "enum": [
            "balanced",
            "harvest",
            "frontier",
            "architectonic"
          ]
        },
        "beta": {
          "type": "number",
          "minimum": 0
        }
      }
    },
    "top_k": {
      "type": "integer",
      "minimum": 0
    },
    "candidates": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/candidate"
      }
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/source"
      }
    },
    "source_diagnostics": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "pattern": "\\S"
      }
    },
    "reported_metrics": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/metric"
      }
    }
  },
  "$defs": {
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "source_id",
        "locator",
        "repo_path",
        "bundle",
        "bundle_relative_path",
        "sha256",
        "size_bytes",
        "availability",
        "integrity_check",
        "required_for_full_replay"
      ],
      "properties": {
        "source_id": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "locator": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "repo_path": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "pattern": "\\S"
            },
            {
              "type": "null"
            }
          ]
        },
        "bundle": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "pattern": "\\S"
            },
            {
              "type": "null"
            }
          ]
        },
        "bundle_relative_path": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "pattern": "\\S"
            },
            {
              "type": "null"
            }
          ]
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "size_bytes": {
          "type": "integer",
          "minimum": 0
        },
        "availability": {
          "enum": [
            "PRESENT",
            "MISSING"
          ]
        },
        "integrity_check": {
          "enum": [
            "MATCHED",
            "NOT_CHECKED"
          ]
        },
        "required_for_full_replay": {
          "type": "boolean"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "availability": {
                "const": "MISSING"
              }
            },
            "required": [
              "availability"
            ]
          },
          "then": {
            "properties": {
              "integrity_check": {
                "const": "NOT_CHECKED"
              }
            }
          }
        }
      ]
    },
    "metric": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "value",
        "source_id"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "value": {
          "anyOf": [
            {
              "type": "number",
              "minimum": 0
            },
            {
              "type": "boolean"
            }
          ]
        },
        "source_id": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        }
      }
    },
    "candidate": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "candidate_id",
        "candidate_type",
        "source_ids",
        "title",
        "suggested_route",
        "descension_target",
        "advisory_only",
        "can_promote_truth"
      ],
      "properties": {
        "candidate_id": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "candidate_type": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "source_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "\\S"
          },
          "uniqueItems": true
        },
        "title": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "suggested_route": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S"
        },
        "descension_target": {
          "type": "string",
          "minLength": 1,
          "pattern": "\\S",
          "description": "Eligibility is checked separately against the v1 descension vocabulary; unknown targets are rejected advisory candidates."
        },
        "advisory_only": {
          "type": "boolean"
        },
        "can_promote_truth": {
          "type": "boolean"
        },
        "expected_certificate_value": {
          "type": "number",
          "minimum": 0
        },
        "expected_obstruction_value": {
          "type": "number",
          "minimum": 0
        },
        "expected_residual_compression": {
          "type": "number",
          "minimum": 0
        },
        "expected_projection_gain": {
          "type": "number",
          "minimum": 0
        },
        "expected_reuse": {
          "type": "number",
          "minimum": 0
        },
        "expected_constructor_reuse": {
          "type": "number",
          "minimum": 0
        },
        "expected_bridge_value": {
          "type": "number",
          "minimum": 0
        },
        "novelty_score": {
          "type": "number",
          "minimum": 0
        },
        "verification_cost": {
          "type": "number",
          "minimum": 0
        },
        "duplicate_risk": {
          "type": "number",
          "minimum": 0
        },
        "overfit_risk": {
          "type": "number",
          "minimum": 0
        },
        "foreign_moisture_risk": {
          "type": "number",
          "minimum": 0
        },
        "notes": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      }
    }
  }
}
