{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://ardur.dev/vibap/spec/mission-declaration/v0.1/mission-declaration-v0.1.schema.json",
  "title": "Mission Declaration v0.1",
  "description": "Mission Declaration (MD) payload object for the Ardur runtime-governance protocol. NOTE on `required` (FIX-R5-M1, 2026-04-29): two members the runtime treats semantically as optional are removed from `required` so the schema and the reference Python verifier agree. `approval_policy` is treated as 'no approval gate' when absent — its presence is a producer choice, not a silent default. `probing_rate_limit` is currently validate-only and has no downstream rate-limiter consuming it; producers SHOULD include both for forward compatibility, but absence does not violate v0.1.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "iss",
    "sub",
    "aud",
    "iat",
    "exp",
    "jti",
    "mission_id",
    "allowed_tool_classes",
    "resource_policies",
    "effect_policies",
    "lineage_budgets",
    "delegation_policy",
    "flow_policies",
    "required_telemetry",
    "receipt_policy",
    "conformance_profile",
    "tool_manifest_digest",
    "revocation_ref",
    "governed_memory_stores"
  ],
  "properties": {
    "iss": {
      "type": "string",
      "minLength": 1
    },
    "sub": {
      "type": "string",
      "minLength": 1
    },
    "aud": {
      "type": "string",
      "minLength": 1
    },
    "iat": {
      "type": "integer",
      "minimum": 0
    },
    "exp": {
      "type": "integer",
      "minimum": 0
    },
    "jti": {
      "type": "string",
      "minLength": 1
    },
    "mission_id": {
      "type": "string",
      "format": "uri",
      "minLength": 1
    },
    "allowed_tool_classes": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "format": "uri",
        "pattern": "^[A-Za-z][A-Za-z0-9+.-]*://"
      }
    },
    "resource_policies": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/resource_policy"
      }
    },
    "effect_policies": {
      "type": "array",
      "minItems": 5,
      "maxItems": 5,
      "items": {
        "$ref": "#/$defs/effect_policy"
      },
      "allOf": [
        {
          "contains": {
            "type": "object",
            "properties": {
              "side_effect_class": {
                "const": "read"
              }
            },
            "required": [
              "side_effect_class"
            ]
          }
        },
        {
          "contains": {
            "type": "object",
            "properties": {
              "side_effect_class": {
                "const": "write"
              }
            },
            "required": [
              "side_effect_class"
            ]
          }
        },
        {
          "contains": {
            "type": "object",
            "properties": {
              "side_effect_class": {
                "const": "network"
              }
            },
            "required": [
              "side_effect_class"
            ]
          }
        },
        {
          "contains": {
            "type": "object",
            "properties": {
              "side_effect_class": {
                "const": "exec"
              }
            },
            "required": [
              "side_effect_class"
            ]
          }
        },
        {
          "contains": {
            "type": "object",
            "properties": {
              "side_effect_class": {
                "const": "external_send"
              }
            },
            "required": [
              "side_effect_class"
            ]
          }
        }
      ]
    },
    "lineage_budgets": {
      "$ref": "#/$defs/lineage_budgets"
    },
    "delegation_policy": {
      "$ref": "#/$defs/delegation_policy"
    },
    "flow_policies": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/flow_policy"
      }
    },
    "required_telemetry": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/telemetry_field"
      }
    },
    "receipt_policy": {
      "$ref": "#/$defs/receipt_policy"
    },
    "conformance_profile": {
      "type": "string",
      "enum": [
        "Delegation-Core",
        "MIC-State",
        "MIC-Evidence"
      ]
    },
    "tool_manifest_digest": {
      "type": "string",
      "pattern": "^sha-256:[0-9a-f]{64}$"
    },
    "revocation_ref": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://[^#]+#idx=[0-9]+$"
    },
    "approval_policy": {
      "$ref": "#/$defs/approval_policy"
    },
    "governed_memory_stores": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/governed_memory_store"
      }
    },
    "probing_rate_limit": {
      "type": "integer",
      "minimum": 1
    },
    "idm_extension": {
      "$ref": "#/$defs/idm_extension"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "conformance_profile": {
            "const": "MIC-Evidence"
          }
        },
        "required": [
          "conformance_profile"
        ]
      },
      "then": {
        "properties": {
          "receipt_policy": {
            "type": "object",
            "properties": {
              "level": {
                "enum": [
                  "counter_signed",
                  "transparency_logged"
                ]
              }
            },
            "required": [
              "level"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "idm_extension": {
            "type": "object",
            "properties": {
              "enabled": {
                "const": true
              }
            },
            "required": [
              "enabled"
            ]
          }
        },
        "required": [
          "idm_extension"
        ]
      },
      "then": {
        "properties": {
          "idm_extension": {
            "required": [
              "enabled",
              "intent_schema_ref"
            ]
          }
        }
      }
    }
  ],
  "$defs": {
    "non_empty_string": {
      "type": "string",
      "minLength": 1
    },
    "side_effect_class": {
      "type": "string",
      "enum": [
        "read",
        "write",
        "network",
        "exec",
        "external_send"
      ]
    },
    "resource_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "family",
        "pattern",
        "sensitivity"
      ],
      "properties": {
        "family": {
          "$ref": "#/$defs/non_empty_string"
        },
        "pattern": {
          "type": "string",
          "minLength": 1,
          "pattern": "^(exact|glob):.+$"
        },
        "sensitivity": {
          "$ref": "#/$defs/non_empty_string"
        }
      }
    },
    "effect_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "side_effect_class",
        "limit"
      ],
      "properties": {
        "side_effect_class": {
          "$ref": "#/$defs/side_effect_class"
        },
        "limit": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "budget_pair": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "reserved",
        "ceiling"
      ],
      "properties": {
        "reserved": {
          "type": "integer",
          "minimum": 0
        },
        "ceiling": {
          "type": "integer",
          "minimum": 0
        }
      }
    },
    "lineage_budgets": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "per_effect_class"
      ],
      "properties": {
        "per_effect_class": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "read",
            "write",
            "network",
            "exec",
            "external_send"
          ],
          "properties": {
            "read": {
              "$ref": "#/$defs/budget_pair"
            },
            "write": {
              "$ref": "#/$defs/budget_pair"
            },
            "network": {
              "$ref": "#/$defs/budget_pair"
            },
            "exec": {
              "$ref": "#/$defs/budget_pair"
            },
            "external_send": {
              "$ref": "#/$defs/budget_pair"
            }
          }
        }
      }
    },
    "delegation_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "max_depth",
        "allowed_child_subjects",
        "attenuation_rules"
      ],
      "properties": {
        "max_depth": {
          "type": "integer",
          "minimum": 0
        },
        "allowed_child_subjects": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1,
            "pattern": "^(exact|glob):.+$"
          }
        },
        "attenuation_rules": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "tool_subset",
              "resource_subset",
              "effect_subset",
              "budget_nonincrease",
              "telemetry_nonweakening",
              "receipt_level_nonweakening",
              "profile_nonweakening",
              "memory_store_subset"
            ]
          }
        }
      }
    },
    "flow_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "from_class",
        "to_class",
        "action"
      ],
      "properties": {
        "from_class": {
          "$ref": "#/$defs/non_empty_string"
        },
        "to_class": {
          "$ref": "#/$defs/non_empty_string"
        },
        "action": {
          "type": "string",
          "enum": [
            "allow",
            "deny"
          ]
        }
      }
    },
    "telemetry_field": {
      "type": "string",
      "enum": [
        "event_id",
        "session_id",
        "timestamp",
        "actor",
        "action_class",
        "tool_name",
        "target",
        "resource_family",
        "content_class",
        "content_provenance",
        "summary",
        "side_effect_class",
        "visibility",
        "parent_event_id",
        "delegation_from",
        "delegation_to",
        "confidence_hint",
        "sensitivity",
        "instruction_bearing",
        "budget_delta",
        "grant_id"
      ]
    },
    "receipt_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "level"
      ],
      "properties": {
        "level": {
          "type": "string",
          "enum": [
            "minimal",
            "counter_signed",
            "transparency_logged"
          ]
        }
      }
    },
    "approval_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "max_approvals_per_hour_per_operator"
      ],
      "properties": {
        "max_approvals_per_hour_per_operator": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "governed_memory_store": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "store_id",
        "resource_family",
        "ttl_s",
        "integrity_policy"
      ],
      "properties": {
        "store_id": {
          "$ref": "#/$defs/non_empty_string"
        },
        "resource_family": {
          "$ref": "#/$defs/non_empty_string"
        },
        "ttl_s": {
          "type": "integer",
          "minimum": 0
        },
        "integrity_policy": {
          "type": "string",
          "enum": [
            "digest_bound",
            "entry_signed",
            "transparency_logged"
          ]
        }
      }
    },
    "idm_extension": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "intent_schema_ref": {
          "type": "string",
          "format": "uri",
          "minLength": 1
        }
      }
    }
  }
}
