{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ecoclouddev.com/schemas/verification-rubric.schema.json",
  "title": "EcoCloud Verification Rubric",
  "description": "The dual-rail verification rubric — composes deterministic checks (schema match, value threshold, denied terms, scope, idempotency) with a probabilistic check (externally-computed LLM-judge score) into a single verdict + signable attestation_basis. The kernel implementing this is `flowdesk-verify-kernel.js`; the kernel never signs (caller provides ES256 keys). Apache-2.0.",
  "type": "object",
  "required": ["rubric"],
  "properties": {
    "task_id": { "type": "string", "description": "The task this verification is bound to (caller-provided)." },
    "agent_uaid": { "type": "string", "description": "The agent's Universal Agent ID (DID-style)." },
    "timestamp": { "type": "string", "format": "date-time", "description": "Caller-provided ISO 8601 timestamp. The kernel does not call Date.now to keep verdicts reproducible." },
    "rubric": {
      "type": "object",
      "properties": {
        "deterministic_checks": {
          "type": "array", "maxItems": 64,
          "items": { "$ref": "#/$defs/deterministic_check" }
        },
        "probabilistic_checks": {
          "type": "array", "maxItems": 64,
          "items": { "$ref": "#/$defs/probabilistic_check" }
        }
      }
    }
  },
  "$defs": {
    "deterministic_check": {
      "oneOf": [
        { "$ref": "#/$defs/schema_match" },
        { "$ref": "#/$defs/value_threshold" },
        { "$ref": "#/$defs/value_range" },
        { "$ref": "#/$defs/literal_match" },
        { "$ref": "#/$defs/denied_terms" },
        { "$ref": "#/$defs/scope_in" },
        { "$ref": "#/$defs/idempotency_key_present" }
      ]
    },
    "probabilistic_check": {
      "oneOf": [ { "$ref": "#/$defs/llm_judge" } ]
    },
    "schema_match": {
      "type": "object", "required": ["type", "target_keys", "payload"],
      "properties": {
        "type": { "const": "schema_match" },
        "label": { "type": "string" },
        "target_keys": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "target_types": { "type": "object", "additionalProperties": { "enum": ["string", "number", "boolean", "object"] } },
        "payload": { "type": "object" },
        "required": { "type": "boolean", "default": true }
      }
    },
    "value_threshold": {
      "type": "object", "required": ["type", "amount", "max"],
      "properties": {
        "type": { "const": "value_threshold" },
        "label": { "type": "string" },
        "amount": { "type": "number", "description": "Proposed amount; verified, never moved." },
        "max": { "type": "number", "exclusiveMinimum": 0 },
        "currency": { "type": "string" },
        "expected_currency": { "type": "string" },
        "required": { "type": "boolean", "default": true }
      }
    },
    "value_range": {
      "type": "object", "required": ["type", "amount", "min", "max"],
      "properties": {
        "type": { "const": "value_range" },
        "label": { "type": "string" },
        "amount": { "type": "number" },
        "min": { "type": "number" },
        "max": { "type": "number" },
        "required": { "type": "boolean", "default": true }
      }
    },
    "literal_match": {
      "type": "object", "required": ["type", "text", "term"],
      "properties": {
        "type": { "const": "literal_match" },
        "label": { "type": "string" },
        "text": { "type": "string", "maxLength": 50000 },
        "term": { "type": "string", "minLength": 1 },
        "required": { "type": "boolean", "default": true }
      }
    },
    "denied_terms": {
      "type": "object", "required": ["type", "text", "terms"],
      "properties": {
        "type": { "const": "denied_terms" },
        "label": { "type": "string" },
        "text": { "type": "string", "maxLength": 50000 },
        "terms": { "type": "array", "items": { "type": "string" }, "minItems": 1, "maxItems": 256 },
        "required": { "type": "boolean", "default": true }
      }
    },
    "scope_in": {
      "type": "object", "required": ["type", "scopes", "required_action"],
      "properties": {
        "type": { "const": "scope_in" },
        "label": { "type": "string" },
        "scopes": { "type": "array", "items": { "type": "string" } },
        "required_action": { "type": "string", "pattern": "^[a-z_]+\\.[a-z_]+$", "description": "Format: resource.verb e.g. tasks.create" },
        "required": { "type": "boolean", "default": true }
      }
    },
    "idempotency_key_present": {
      "type": "object", "required": ["type", "key"],
      "properties": {
        "type": { "const": "idempotency_key_present" },
        "label": { "type": "string" },
        "key": { "type": "string", "minLength": 8, "maxLength": 256 },
        "required": { "type": "boolean", "default": true }
      }
    },
    "llm_judge": {
      "type": "object", "required": ["type", "score", "threshold", "criteria"],
      "properties": {
        "type": { "const": "llm_judge" },
        "label": { "type": "string" },
        "score": { "type": "number", "minimum": 0, "maximum": 1, "description": "Externally-computed [0,1] score from the LLM-as-judge call. The kernel never calls the LLM." },
        "threshold": { "type": "number", "minimum": 0, "maximum": 1 },
        "criteria": { "type": "string", "minLength": 1 },
        "required": { "type": "boolean", "default": true }
      }
    }
  }
}
