{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:ai-agent-controlled-executor-handoff-v1",
  "title": "AWOOOI AI Agent controlled executor handoff v1",
  "description": "P2-415 承接 P2-409 controlled apply queue，建立 high 風險候選交給受控 executor 前的 handoff readback：allowlist、Ansible check-mode、rollback、post-action verifier、Telegram evidence、KM / PlayBook trust 回寫都必須可讀。此 schema 不授權 live apply、Telegram send、Bot API、secret read、paid API、host write、kubectl 或不可逆操作。",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "program_status",
    "source_refs",
    "source_readbacks",
    "handoff_truth",
    "executor_handoff_packets",
    "executor_routes",
    "verifier_bindings",
    "learning_writeback_contracts",
    "activation_boundaries",
    "display_redaction_contract",
    "rollups",
    "next_actions"
  ],
  "properties": {
    "schema_version": { "type": "string", "const": "ai_agent_controlled_executor_handoff_v1" },
    "generated_at": { "type": "string", "minLength": 1 },
    "program_status": {
      "type": "object",
      "required": [
        "overall_completion_percent",
        "current_priority",
        "current_task_id",
        "next_task_id",
        "read_only_mode",
        "runtime_authority",
        "status_note"
      ],
      "properties": {
        "overall_completion_percent": { "type": "integer", "const": 100 },
        "current_priority": { "type": "string", "const": "P0" },
        "current_task_id": { "type": "string", "const": "P2-415" },
        "next_task_id": { "type": "string", "const": "P2-416" },
        "read_only_mode": { "type": "boolean", "const": true },
        "runtime_authority": { "type": "string", "const": "controlled_executor_handoff_readback_no_live_apply" },
        "status_note": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "source_refs": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
    "source_readbacks": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/source_readback" } },
    "handoff_truth": { "type": "object", "additionalProperties": { "type": ["boolean", "integer", "string"] } },
    "executor_handoff_packets": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/executor_handoff_packet" } },
    "executor_routes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/executor_route" } },
    "verifier_bindings": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/verifier_binding" } },
    "learning_writeback_contracts": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/learning_writeback_contract" } },
    "activation_boundaries": { "type": "object", "additionalProperties": { "type": "boolean" } },
    "display_redaction_contract": { "type": "object", "additionalProperties": { "type": ["boolean", "array", "string"] } },
    "rollups": { "type": "object", "additionalProperties": { "type": "integer" } },
    "next_actions": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/next_action" } }
  },
  "$defs": {
    "source_readback": {
      "type": "object",
      "required": ["readback_id", "source_schema_version", "source_ref", "endpoint", "owner_agent", "status", "key_readback", "next_action"],
      "properties": {
        "readback_id": { "type": "string", "minLength": 1 },
        "source_schema_version": { "type": "string", "minLength": 1 },
        "source_ref": { "type": "string", "minLength": 1 },
        "endpoint": { "type": "string", "minLength": 1 },
        "owner_agent": { "type": "string", "enum": ["openclaw", "hermes", "nemotron", "sre", "security", "devops"] },
        "status": { "type": "string", "minLength": 1 },
        "key_readback": { "type": "string", "minLength": 1 },
        "next_action": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "executor_handoff_packet": {
      "type": "object",
      "required": [
        "packet_id",
        "source_queue_item_id",
        "display_name",
        "risk_tier",
        "owner_agent",
        "executor_agent",
        "executor_type",
        "handoff_status",
        "controlled_route_id",
        "playbook_ref",
        "mcp_tool_ref",
        "check_mode_ref",
        "verifier_ref",
        "rollback_ref",
        "telegram_evidence_ref",
        "km_writeback_ref",
        "playbook_trust_ref",
        "allowlist_match",
        "check_mode_passed",
        "rollback_plan_ready",
        "post_action_verifier_ready",
        "telegram_evidence_ready",
        "km_writeback_ready",
        "playbook_trust_writeback_ready",
        "owner_response_required",
        "break_glass_required",
        "controlled_executor_handoff_allowed",
        "live_apply_performed",
        "side_effect_count",
        "blocked_runtime_actions",
        "next_gate"
      ],
      "properties": {
        "packet_id": { "type": "string", "minLength": 1 },
        "source_queue_item_id": { "type": "string", "minLength": 1 },
        "display_name": { "type": "string", "minLength": 1 },
        "risk_tier": { "type": "string", "enum": ["high", "critical"] },
        "owner_agent": { "type": "string", "enum": ["openclaw", "hermes", "nemotron", "sre", "security", "devops"] },
        "executor_agent": { "type": "string", "enum": ["openclaw", "hermes", "nemotron", "sre", "security", "devops"] },
        "executor_type": { "type": "string", "enum": ["ansible_playbook", "mcp_tool_route", "telegram_gateway_queue", "km_playbook_writer", "readback_verifier", "break_glass_only"] },
        "handoff_status": { "type": "string", "enum": ["ready_for_controlled_executor", "critical_break_glass_only", "blocked_missing_check_mode", "blocked_missing_verifier", "blocked_missing_learning_writeback"] },
        "controlled_route_id": { "type": "string", "minLength": 1 },
        "playbook_ref": { "type": "string", "minLength": 1 },
        "mcp_tool_ref": { "type": "string", "minLength": 1 },
        "check_mode_ref": { "type": "string", "minLength": 1 },
        "verifier_ref": { "type": "string", "minLength": 1 },
        "rollback_ref": { "type": "string", "minLength": 1 },
        "telegram_evidence_ref": { "type": "string", "minLength": 1 },
        "km_writeback_ref": { "type": "string", "minLength": 1 },
        "playbook_trust_ref": { "type": "string", "minLength": 1 },
        "allowlist_match": { "type": "boolean" },
        "check_mode_passed": { "type": "boolean" },
        "rollback_plan_ready": { "type": "boolean" },
        "post_action_verifier_ready": { "type": "boolean" },
        "telegram_evidence_ready": { "type": "boolean" },
        "km_writeback_ready": { "type": "boolean" },
        "playbook_trust_writeback_ready": { "type": "boolean" },
        "owner_response_required": { "type": "boolean" },
        "break_glass_required": { "type": "boolean" },
        "controlled_executor_handoff_allowed": { "type": "boolean" },
        "live_apply_performed": { "type": "boolean", "const": false },
        "side_effect_count": { "type": "integer", "const": 0 },
        "blocked_runtime_actions": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "next_gate": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "executor_route": {
      "type": "object",
      "required": ["route_id", "display_name", "executor_agent", "route_status", "required_inputs", "blocked_actions", "live_apply_allowed_by_this_readback"],
      "properties": {
        "route_id": { "type": "string", "minLength": 1 },
        "display_name": { "type": "string", "minLength": 1 },
        "executor_agent": { "type": "string", "enum": ["openclaw", "hermes", "nemotron", "sre", "security", "devops"] },
        "route_status": { "type": "string", "enum": ["ready_for_handoff", "blocked_by_policy"] },
        "required_inputs": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "blocked_actions": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "live_apply_allowed_by_this_readback": { "type": "boolean", "const": false }
      },
      "additionalProperties": false
    },
    "verifier_binding": {
      "type": "object",
      "required": ["binding_id", "display_name", "owner_agent", "required_before_dispatch", "ready_count", "blocked_count", "failure_if_missing"],
      "properties": {
        "binding_id": { "type": "string", "minLength": 1 },
        "display_name": { "type": "string", "minLength": 1 },
        "owner_agent": { "type": "string", "enum": ["openclaw", "hermes", "nemotron", "sre", "security", "devops"] },
        "required_before_dispatch": { "type": "boolean", "const": true },
        "ready_count": { "type": "integer", "minimum": 0 },
        "blocked_count": { "type": "integer", "minimum": 0 },
        "failure_if_missing": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "learning_writeback_contract": {
      "type": "object",
      "required": ["contract_id", "display_name", "owner_agent", "target_store", "writeback_status", "required_fields", "runtime_write_performed"],
      "properties": {
        "contract_id": { "type": "string", "minLength": 1 },
        "display_name": { "type": "string", "minLength": 1 },
        "owner_agent": { "type": "string", "enum": ["openclaw", "hermes", "nemotron", "sre", "security", "devops"] },
        "target_store": { "type": "string", "minLength": 1 },
        "writeback_status": { "type": "string", "enum": ["ready_for_executor_receipt", "blocked_by_policy"] },
        "required_fields": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "runtime_write_performed": { "type": "boolean", "const": false }
      },
      "additionalProperties": false
    },
    "next_action": {
      "type": "object",
      "required": ["task_id", "priority", "summary", "gate"],
      "properties": {
        "task_id": { "type": "string", "minLength": 1 },
        "priority": { "type": "string", "minLength": 1 },
        "summary": { "type": "string", "minLength": 1 },
        "gate": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
