{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:gitea-inventory-owner-attestation-response-v1",
  "title": "Gitea 清冊 Owner Attestation Response 收件契約 v1",
  "description": "定義 owner 回覆 S4.7 coverage attestation 時的收件欄位、驗收規則與拒收規則。此 schema 不授權 token 收集、Gitea/GitHub 寫入、refs sync 或 GitHub primary cutover。",
  "type": "object",
  "required": [
    "schema_version",
    "status",
    "date",
    "mode",
    "runtime_execution_authorized",
    "source_contract",
    "target_contract",
    "source_indexes",
    "summary",
    "response_templates",
    "owner_response_intake_handoff_queue",
    "owner_response_metadata_intake_envelope",
    "acceptance_checks",
    "rejection_rules",
    "allowed_outputs",
    "forbidden_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "gitea_inventory_owner_attestation_response_v1"
    },
    "status": {
      "type": "string",
      "enum": ["draft_waiting_owner_response"]
    },
    "date": {
      "type": "string"
    },
    "mode": {
      "type": "string",
      "enum": ["owner_response_intake_only"]
    },
    "runtime_execution_authorized": {
      "type": "boolean",
      "const": false
    },
    "source_contract": {
      "type": "string",
      "const": "gitea_inventory_coverage_attestation_v1"
    },
    "target_contract": {
      "type": "string",
      "const": "gitea_repo_inventory_v1"
    },
    "source_indexes": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "owner_response_status",
        "required_response_item_count",
        "received_response_count",
        "accepted_response_count",
        "rejected_response_count",
        "response_template_count",
        "owner_response_template_status_count",
        "owner_response_audit_event_template_count",
        "owner_response_redaction_example_count",
        "owner_response_display_section_count",
        "owner_response_request_packet_count",
        "owner_response_collection_check_count",
        "owner_response_intake_handoff_queue_count",
        "owner_response_intake_handoff_queue_ready_count",
        "owner_response_intake_handoff_queue_received_count",
        "owner_response_intake_handoff_queue_accepted_count",
        "owner_response_intake_handoff_queue_runtime_gate_count",
        "owner_response_intake_handoff_queue_raw_payload_allowed",
        "owner_response_intake_handoff_queue_action_buttons_allowed",
        "owner_response_metadata_intake_field_count",
        "owner_response_metadata_intake_required_count",
        "owner_response_metadata_intake_filled_count",
        "owner_response_metadata_intake_received_count",
        "owner_response_metadata_intake_accepted_count",
        "owner_response_metadata_intake_runtime_gate_count",
        "owner_response_metadata_intake_redacted_ref_required",
        "owner_response_metadata_intake_raw_payload_allowed",
        "owner_response_metadata_intake_secret_plaintext_allowed",
        "owner_response_metadata_intake_action_buttons_allowed",
        "intake_preflight_check_count",
        "intake_outcome_lane_count",
        "acceptance_check_count",
        "rejection_rule_count",
        "token_value_collection_allowed",
        "raw_secret_allowed",
        "repo_write_allowed",
        "refs_sync_allowed",
        "github_primary_switch_authorized",
        "action_buttons_allowed"
      ],
      "properties": {
        "owner_response_status": {
          "type": "string",
          "enum": ["waiting_owner_response"]
        },
        "required_response_item_count": {"type": "integer", "minimum": 0},
        "received_response_count": {"type": "integer", "minimum": 0},
        "accepted_response_count": {"type": "integer", "minimum": 0},
        "rejected_response_count": {"type": "integer", "minimum": 0},
        "response_template_count": {"type": "integer", "minimum": 0},
        "owner_response_template_status_count": {"type": "integer", "minimum": 0},
        "owner_response_audit_event_template_count": {"type": "integer", "minimum": 0},
        "owner_response_redaction_example_count": {"type": "integer", "minimum": 0},
        "owner_response_display_section_count": {"type": "integer", "minimum": 0},
        "owner_response_request_packet_count": {"type": "integer", "minimum": 0},
        "owner_response_collection_check_count": {"type": "integer", "minimum": 0},
        "owner_response_intake_handoff_queue_count": {"type": "integer", "minimum": 0},
        "owner_response_intake_handoff_queue_ready_count": {"type": "integer", "minimum": 0},
        "owner_response_intake_handoff_queue_received_count": {"type": "integer", "minimum": 0},
        "owner_response_intake_handoff_queue_accepted_count": {"type": "integer", "minimum": 0},
        "owner_response_intake_handoff_queue_runtime_gate_count": {"type": "integer", "minimum": 0},
        "owner_response_intake_handoff_queue_raw_payload_allowed": {
          "type": "boolean",
          "const": false
        },
        "owner_response_intake_handoff_queue_action_buttons_allowed": {
          "type": "boolean",
          "const": false
        },
        "owner_response_metadata_intake_field_count": {"type": "integer", "minimum": 0},
        "owner_response_metadata_intake_required_count": {"type": "integer", "minimum": 0},
        "owner_response_metadata_intake_filled_count": {"type": "integer", "const": 0},
        "owner_response_metadata_intake_received_count": {"type": "integer", "const": 0},
        "owner_response_metadata_intake_accepted_count": {"type": "integer", "const": 0},
        "owner_response_metadata_intake_runtime_gate_count": {"type": "integer", "const": 0},
        "owner_response_metadata_intake_redacted_ref_required": {
          "type": "boolean",
          "const": true
        },
        "owner_response_metadata_intake_raw_payload_allowed": {
          "type": "boolean",
          "const": false
        },
        "owner_response_metadata_intake_secret_plaintext_allowed": {
          "type": "boolean",
          "const": false
        },
        "owner_response_metadata_intake_action_buttons_allowed": {
          "type": "boolean",
          "const": false
        },
        "intake_preflight_check_count": {"type": "integer", "minimum": 0},
        "intake_outcome_lane_count": {"type": "integer", "minimum": 0},
        "acceptance_check_count": {"type": "integer", "minimum": 0},
        "rejection_rule_count": {"type": "integer", "minimum": 0},
        "token_value_collection_allowed": {
          "type": "boolean",
          "const": false
        },
        "raw_secret_allowed": {
          "type": "boolean",
          "const": false
        },
        "repo_write_allowed": {
          "type": "boolean",
          "const": false
        },
        "refs_sync_allowed": {
          "type": "boolean",
          "const": false
        },
        "github_primary_switch_authorized": {
          "type": "boolean",
          "const": false
        },
        "action_buttons_allowed": {
          "type": "boolean",
          "const": false
        }
      },
      "additionalProperties": false
    },
    "response_templates": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "template_id",
          "attestation_item_id",
          "title",
          "required_owner_fields",
          "acceptable_decisions",
          "minimum_evidence_refs",
          "acceptance_criteria",
          "rejection_conditions",
          "allowed_outputs",
          "execution_authorized"
        ],
        "properties": {
          "template_id": {"type": "string"},
          "attestation_item_id": {"type": "string"},
          "title": {"type": "string"},
          "required_owner_fields": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "acceptable_decisions": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "minimum_evidence_refs": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "acceptance_criteria": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "rejection_conditions": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "allowed_outputs": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "execution_authorized": {
            "type": "boolean",
            "const": false
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_template_statuses": {
      "type": "array",
      "description": "S4.9 五個 response templates 的逐項收件狀態；只供 AwoooP 顯示，不代表 approval 或 execution queue。",
      "items": {
        "type": "object",
        "required": [
          "template_id",
          "attestation_item_id",
          "display_order",
          "collection_status",
          "request_status",
          "received_response_count",
          "accepted_response_count",
          "rejected_response_count",
          "latest_outcome_lane",
          "next_owner_action",
          "awooop_display_mode",
          "execution_authorized",
          "not_approval",
          "still_forbidden"
        ],
        "properties": {
          "template_id": {"type": "string"},
          "attestation_item_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "collection_status": {"type": "string", "enum": ["waiting_owner_response"]},
          "request_status": {"type": "string", "enum": ["request_ready_not_sent"]},
          "received_response_count": {"type": "integer", "minimum": 0},
          "accepted_response_count": {"type": "integer", "minimum": 0},
          "rejected_response_count": {"type": "integer", "minimum": 0},
          "latest_outcome_lane": {"type": "string", "enum": ["keep_waiting_owner_response"]},
          "next_owner_action": {"type": "string"},
          "awooop_display_mode": {"type": "string", "enum": ["display_template_status_only"]},
          "execution_authorized": {
            "type": "boolean",
            "const": false
          },
          "not_approval": {
            "type": "boolean",
            "const": true
          },
          "still_forbidden": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_audit_event_templates": {
      "type": "array",
      "description": "AwoooP 可照此格式記錄 S4.9 owner response 流程的脫敏 audit metadata；此欄位只是模板，尚未代表 runtime ingestion。",
      "items": {
        "type": "object",
        "required": [
          "event_template_id",
          "display_order",
          "event_status",
          "trigger",
          "purpose",
          "allowed_metadata_fields",
          "forbidden_payloads",
          "emitted_event_count",
          "stored_raw_payload_allowed",
          "awooop_display_mode",
          "execution_authorized",
          "not_approval"
        ],
        "properties": {
          "event_template_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "event_status": {"type": "string", "enum": ["template_only_not_emitted"]},
          "trigger": {"type": "string"},
          "purpose": {"type": "string"},
          "allowed_metadata_fields": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "forbidden_payloads": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "emitted_event_count": {"type": "integer", "minimum": 0},
          "stored_raw_payload_allowed": {
            "type": "boolean",
            "const": false
          },
          "awooop_display_mode": {"type": "string", "enum": ["display_audit_template_only"]},
          "execution_authorized": {
            "type": "boolean",
            "const": false
          },
          "not_approval": {
            "type": "boolean",
            "const": true
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_redaction_examples": {
      "type": "array",
      "description": "Owner 回覆 S4.9 時可參考的脫敏範例；只供 AwoooP 顯示，不代表收件、驗收或執行授權。",
      "items": {
        "type": "object",
        "required": [
          "example_id",
          "display_order",
          "example_status",
          "category",
          "safe_response_shape",
          "required_redactions",
          "forbidden_raw_values",
          "stored_raw_payload_allowed",
          "awooop_display_mode",
          "execution_authorized",
          "not_approval"
        ],
        "properties": {
          "example_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "example_status": {"type": "string", "enum": ["template_example_only"]},
          "category": {"type": "string"},
          "safe_response_shape": {"type": "array", "items": {"type": "string"}, "minItems": 1},
          "required_redactions": {"type": "array", "items": {"type": "string"}, "minItems": 1},
          "forbidden_raw_values": {"type": "array", "items": {"type": "string"}, "minItems": 1},
          "stored_raw_payload_allowed": {"type": "boolean", "const": false},
          "awooop_display_mode": {"type": "string", "enum": ["display_redaction_example_only"]},
          "execution_authorized": {"type": "boolean", "const": false},
          "not_approval": {"type": "boolean", "const": true}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_display_sections": {
      "type": "array",
      "description": "AwoooP 顯示 S4.9 owner response 收件包時的只讀 UI 區塊順序；只供顯示，不代表收件、審核或執行。",
      "items": {
        "type": "object",
        "required": [
          "section_id",
          "display_order",
          "section_status",
          "source_field",
          "purpose",
          "allowed_ui_actions",
          "forbidden_ui_actions",
          "execution_authorized",
          "not_approval"
        ],
        "properties": {
          "section_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "section_status": {"type": "string", "enum": ["display_contract_only"]},
          "source_field": {"type": "string"},
          "purpose": {"type": "string"},
          "allowed_ui_actions": {"type": "array", "items": {"type": "string"}, "minItems": 1},
          "forbidden_ui_actions": {"type": "array", "items": {"type": "string"}, "minItems": 1},
          "execution_authorized": {"type": "boolean", "const": false},
          "not_approval": {"type": "boolean", "const": true}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_intake_handoff_queue": {
      "type": "array",
      "description": "S4.9 owner response 收件前 handoff queue；只供 AwoooP / IwoooS 顯示下一個 owner 要補的脫敏中繼資料，不代表 request sent、received、accepted 或 runtime gate。",
      "items": {
        "type": "object",
        "required": [
          "handoff_lane_id",
          "display_order",
          "source_template_id",
          "template_label",
          "handoff_status",
          "required_owner_field_count",
          "required_owner_fields",
          "current_blocker",
          "next_safe_step",
          "received_response_count",
          "accepted_response_count",
          "runtime_gate_count",
          "raw_payload_allowed",
          "secret_plaintext_allowed",
          "action_buttons_allowed",
          "execution_authorized",
          "not_approval",
          "still_forbidden"
        ],
        "properties": {
          "handoff_lane_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "source_template_id": {"type": "string"},
          "template_label": {"type": "string"},
          "handoff_status": {"type": "string", "enum": ["waiting_owner_response_metadata"]},
          "required_owner_field_count": {"type": "integer", "minimum": 1},
          "required_owner_fields": {"type": "array", "items": {"type": "string"}, "minItems": 1},
          "current_blocker": {"type": "string"},
          "next_safe_step": {"type": "string"},
          "received_response_count": {"type": "integer", "const": 0},
          "accepted_response_count": {"type": "integer", "const": 0},
          "runtime_gate_count": {"type": "integer", "const": 0},
          "raw_payload_allowed": {"type": "boolean", "const": false},
          "secret_plaintext_allowed": {"type": "boolean", "const": false},
          "action_buttons_allowed": {"type": "boolean", "const": false},
          "execution_authorized": {"type": "boolean", "const": false},
          "not_approval": {"type": "boolean", "const": true},
          "still_forbidden": {"type": "array", "items": {"type": "string"}, "minItems": 1}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_metadata_intake_envelope": {
      "type": "array",
      "description": "S4.9 owner response 的必填中繼資料 envelope；只允許脫敏欄位與 reference pointer，不代表已收件、已接受或 runtime gate。",
      "items": {
        "type": "object",
        "required": [
          "field_id",
          "display_order",
          "source_required_field",
          "field_label",
          "field_status",
          "intake_mode",
          "required",
          "filled_count",
          "received_response_count",
          "accepted_response_count",
          "runtime_gate_count",
          "redacted_reference_required",
          "raw_payload_allowed",
          "secret_plaintext_allowed",
          "action_buttons_allowed",
          "execution_authorized",
          "not_approval",
          "still_forbidden"
        ],
        "properties": {
          "field_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "source_required_field": {"type": "string"},
          "field_label": {"type": "string"},
          "field_status": {"type": "string", "enum": ["waiting_owner_response_metadata"]},
          "intake_mode": {"type": "string"},
          "required": {"type": "boolean", "const": true},
          "filled_count": {"type": "integer", "const": 0},
          "received_response_count": {"type": "integer", "const": 0},
          "accepted_response_count": {"type": "integer", "const": 0},
          "runtime_gate_count": {"type": "integer", "const": 0},
          "redacted_reference_required": {"type": "boolean", "const": true},
          "raw_payload_allowed": {"type": "boolean", "const": false},
          "secret_plaintext_allowed": {"type": "boolean", "const": false},
          "action_buttons_allowed": {"type": "boolean", "const": false},
          "execution_authorized": {"type": "boolean", "const": false},
          "not_approval": {"type": "boolean", "const": true},
          "still_forbidden": {"type": "array", "items": {"type": "string"}, "minItems": 1}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "owner_response_request_packet": {
      "type": "object",
      "description": "AwoooP 可直接顯示給 owner 的 S4.9 回覆請求；只說明要填什麼與不得貼什麼，不授權任何執行。",
      "required": [
        "request_id",
        "display_status",
        "requested_packet",
        "required_response_item_count",
        "requested_template_ids",
        "owner_instruction_summary",
        "allowed_response_fields",
        "evidence_ref_rules",
        "forbidden_payloads",
        "allowed_submission_modes",
        "awooop_display_mode",
        "execution_authorized",
        "not_approval",
        "still_forbidden"
      ],
      "properties": {
        "request_id": {"type": "string"},
        "display_status": {"type": "string", "enum": ["ready_to_request_owner_response"]},
        "requested_packet": {"type": "string"},
        "required_response_item_count": {"type": "integer", "minimum": 0},
        "requested_template_ids": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "owner_instruction_summary": {"type": "string"},
        "allowed_response_fields": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "evidence_ref_rules": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "forbidden_payloads": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "allowed_submission_modes": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "awooop_display_mode": {"type": "string", "enum": ["display_owner_response_request_only"]},
        "execution_authorized": {
          "type": "boolean",
          "const": false
        },
        "not_approval": {
          "type": "boolean",
          "const": true
        },
        "still_forbidden": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        }
      },
      "additionalProperties": false
    },
    "owner_response_collection_checks": {
      "type": "array",
      "description": "AwoooP 顯示 request packet 到收回 owner response 之間的只讀收件檢查；不得把 request sent 誤判為 response received / accepted。",
      "items": {
        "type": "object",
        "required": [
          "check_id",
          "display_order",
          "title",
          "required",
          "pass_condition",
          "failure_lane",
          "awooop_display",
          "execution_authorized",
          "not_approval"
        ],
        "properties": {
          "check_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "title": {"type": "string"},
          "required": {"type": "boolean"},
          "pass_condition": {"type": "string"},
          "failure_lane": {"type": "string"},
          "awooop_display": {"type": "string"},
          "execution_authorized": {
            "type": "boolean",
            "const": false
          },
          "not_approval": {
            "type": "boolean",
            "const": true
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "intake_preflight_checks": {
      "type": "array",
      "description": "AwoooP 收到 S4.9 owner response 前後可執行的只讀 preflight；只分類可收、補證或隔離，不授權任何執行。",
      "items": {
        "type": "object",
        "required": [
          "check_id",
          "display_order",
          "title",
          "required",
          "pass_condition",
          "failure_lane",
          "awooop_display",
          "execution_authorized"
        ],
        "properties": {
          "check_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "title": {"type": "string"},
          "required": {"type": "boolean"},
          "pass_condition": {"type": "string"},
          "failure_lane": {"type": "string"},
          "awooop_display": {
            "type": "string",
            "enum": [
              "ready_for_owner_review",
              "request_more_evidence",
              "quarantine_sensitive_payload",
              "reject_execution_request"
            ]
          },
          "execution_authorized": {
            "type": "boolean",
            "const": false
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "intake_outcome_lanes": {
      "type": "array",
      "description": "AwoooP 顯示 S4.9 preflight 結果的只讀 outcome lanes；只顯示下一步，不授權 inventory、migration、repo、refs 或 primary 動作。",
      "items": {
        "type": "object",
        "required": [
          "lane_id",
          "display_order",
          "title",
          "when",
          "awooop_action",
          "allowed_outputs",
          "still_forbidden",
          "execution_authorized",
          "not_approval"
        ],
        "properties": {
          "lane_id": {
            "type": "string",
            "enum": [
              "ready_for_owner_review",
              "request_more_evidence",
              "quarantine_sensitive_payload",
              "reject_execution_request",
              "keep_waiting_owner_response"
            ]
          },
          "display_order": {"type": "integer", "minimum": 1},
          "title": {"type": "string"},
          "when": {"type": "string"},
          "awooop_action": {
            "type": "string",
            "enum": [
              "display_ready_for_owner_review",
              "display_request_more_evidence",
              "route_to_mirror_quarantine",
              "reject_execution_request",
              "keep_waiting_owner_response"
            ]
          },
          "allowed_outputs": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "still_forbidden": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "execution_authorized": {
            "type": "boolean",
            "const": false
          },
          "not_approval": {
            "type": "boolean",
            "const": true
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "acceptance_checks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "check_id",
          "title",
          "required",
          "pass_condition",
          "failure_lane",
          "execution_authorized"
        ],
        "properties": {
          "check_id": {"type": "string"},
          "title": {"type": "string"},
          "required": {"type": "boolean"},
          "pass_condition": {"type": "string"},
          "failure_lane": {"type": "string"},
          "execution_authorized": {
            "type": "boolean",
            "const": false
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "rejection_rules": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "allowed_outputs": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "forbidden_actions": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    }
  },
  "additionalProperties": false
}
