{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:source-control-workflow-secret-name-owner-response-v1",
  "title": "Source Control Workflow / Secret Name Owner Response 收件契約 v1",
  "description": "定義 owner 回覆 workflow / webhook / runner / deploy key / branch protection / CODEOWNERS / repository secret 名稱 parity 時的收件欄位、驗收規則與拒收規則。此 schema 不授權收集 secret value、使用 write token、修改 workflow/webhook/runner/deploy key/branch protection/secret、建立 repo、sync refs 或切換 GitHub primary。",
  "type": "object",
  "required": [
    "schema_version",
    "status",
    "date",
    "mode",
    "runtime_execution_authorized",
    "source_contract",
    "target_contract",
    "source_indexes",
    "summary",
    "workflow_secret_owner_handoff_preflight_checks",
    "workflow_secret_owner_handoff_packet",
    "post_dispatch_invariants",
    "response_templates",
    "acceptance_checks",
    "rejection_rules",
    "allowed_outputs",
    "forbidden_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "source_control_workflow_secret_name_owner_response_v1"
    },
    "status": {
      "type": "string",
      "enum": ["draft_waiting_owner_response"]
    },
    "date": {
      "type": "string"
    },
    "mode": {
      "type": "string",
      "enum": ["owner_workflow_secret_name_response_intake_only"]
    },
    "runtime_execution_authorized": {
      "type": "boolean",
      "const": false
    },
    "source_contract": {
      "type": "string",
      "const": "source_control_workflow_secret_name_inventory_v1"
    },
    "target_contract": {
      "type": "string",
      "const": "source_control_workflow_secret_name_export_request_v1"
    },
    "source_indexes": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "summary": {
      "type": "object",
      "required": [
        "owner_response_status",
        "candidate_repo_count",
        "in_scope_repo_count",
        "export_request_count",
        "export_lane_count",
        "local_evidence_repo_count",
        "local_workflow_file_count",
        "local_referenced_secret_name_count",
        "owner_response_request_packet_count",
        "owner_response_template_status_count",
        "owner_response_audit_event_template_count",
        "owner_response_redaction_example_count",
        "owner_response_collection_check_count",
        "intake_preflight_check_count",
        "response_template_count",
        "received_response_count",
        "accepted_response_count",
        "rejected_response_count",
        "acceptance_check_count",
        "rejection_rule_count",
        "secret_value_collection_allowed",
        "write_token_allowed",
        "workflow_modification_authorized",
        "webhook_modification_authorized",
        "runner_change_authorized",
        "deploy_key_change_authorized",
        "branch_protection_change_authorized",
        "repo_secret_change_authorized",
        "github_hosted_runner_enable_authorized",
        "refs_sync_authorized",
        "github_primary_switch_authorized",
        "action_buttons_allowed",
        "workflow_secret_owner_handoff_package_ready",
        "workflow_secret_owner_handoff_completion_percent",
        "workflow_secret_owner_handoff_check_count",
        "workflow_secret_owner_handoff_packet_field_count",
        "workflow_secret_owner_request_dispatch_authorized",
        "secret_name_parity_complete",
        "secret_value_or_hash_collection_allowed",
        "workflow_secret_owner_response_handoff_not_approval"
      ],
      "properties": {
        "owner_response_status": {"type": "string", "enum": ["waiting_owner_response"]},
        "candidate_repo_count": {"type": "integer", "minimum": 0},
        "in_scope_repo_count": {"type": "integer", "minimum": 0},
        "export_request_count": {"type": "integer", "minimum": 0},
        "export_lane_count": {"type": "integer", "minimum": 0},
        "local_evidence_repo_count": {"type": "integer", "minimum": 0},
        "local_workflow_file_count": {"type": "integer", "minimum": 0},
        "local_referenced_secret_name_count": {"type": "integer", "minimum": 0},
        "owner_response_request_packet_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_collection_check_count": {"type": "integer", "minimum": 0},
        "intake_preflight_check_count": {"type": "integer", "minimum": 0},
        "response_template_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},
        "acceptance_check_count": {"type": "integer", "minimum": 0},
        "rejection_rule_count": {"type": "integer", "minimum": 0},
        "secret_value_collection_allowed": {"type": "boolean", "const": false},
        "write_token_allowed": {"type": "boolean", "const": false},
        "workflow_modification_authorized": {"type": "boolean", "const": false},
        "webhook_modification_authorized": {"type": "boolean", "const": false},
        "runner_change_authorized": {"type": "boolean", "const": false},
        "deploy_key_change_authorized": {"type": "boolean", "const": false},
        "branch_protection_change_authorized": {"type": "boolean", "const": false},
        "repo_secret_change_authorized": {"type": "boolean", "const": false},
        "github_hosted_runner_enable_authorized": {"type": "boolean", "const": false},
        "refs_sync_authorized": {"type": "boolean", "const": false},
        "github_primary_switch_authorized": {"type": "boolean", "const": false},
        "action_buttons_allowed": {"type": "boolean", "const": false},
        "workflow_secret_owner_handoff_package_ready": {"type": "boolean", "const": true},
        "workflow_secret_owner_handoff_completion_percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "workflow_secret_owner_handoff_check_count": {"type": "integer", "minimum": 0},
        "workflow_secret_owner_handoff_packet_field_count": {"type": "integer", "minimum": 0},
        "workflow_secret_owner_request_dispatch_authorized": {"type": "boolean", "const": false},
        "secret_name_parity_complete": {"type": "boolean", "const": false},
        "secret_value_or_hash_collection_allowed": {"type": "boolean", "const": false},
        "workflow_secret_owner_response_handoff_not_approval": {"type": "boolean", "const": true}
      },
      "additionalProperties": false
    },
    "workflow_secret_owner_handoff_preflight_checks": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "check_id",
          "display_order",
          "check",
          "current_status",
          "execution_authorized"
        ],
        "properties": {
          "check_id": {"type": "string"},
          "display_order": {"type": "integer", "minimum": 1},
          "check": {"type": "string"},
          "current_status": {
            "type": "string",
            "enum": ["defined_not_dispatched"]
          },
          "execution_authorized": {"type": "boolean", "const": false}
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "workflow_secret_owner_handoff_packet": {
      "type": "object",
      "required": [
        "request_id",
        "stage_id",
        "source_evidence_summary",
        "requested_templates",
        "recipient_role_or_team_required",
        "required_response_fields",
        "allowed_metadata",
        "forbidden_inputs",
        "not_approval",
        "execution_authorized"
      ],
      "properties": {
        "request_id": {"type": "string"},
        "stage_id": {"type": "string"},
        "source_evidence_summary": {
          "type": "object",
          "required": [
            "local_evidence_repo_count",
            "local_workflow_file_count",
            "local_referenced_secret_name_count",
            "runner_label_count"
          ],
          "properties": {
            "local_evidence_repo_count": {"type": "integer", "minimum": 0},
            "local_workflow_file_count": {"type": "integer", "minimum": 0},
            "local_referenced_secret_name_count": {"type": "integer", "minimum": 0},
            "runner_label_count": {"type": "integer", "minimum": 0}
          },
          "additionalProperties": false
        },
        "requested_templates": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "recipient_role_or_team_required": {"type": "boolean", "const": true},
        "required_response_fields": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "allowed_metadata": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "forbidden_inputs": {
          "type": "array",
          "items": {"type": "string"},
          "minItems": 1
        },
        "not_approval": {"type": "boolean", "const": true},
        "execution_authorized": {"type": "boolean", "const": false}
      },
      "additionalProperties": false
    },
    "post_dispatch_invariants": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    },
    "owner_response_template_statuses": {
      "type": "array",
      "description": "S4.12 五個 workflow / secret name response templates 的逐項收件狀態；只供 AwoooP 顯示，不代表 request sent、response received、workflow / secret execution queue 或 primary readiness。",
      "items": {
        "type": "object",
        "required": [
          "template_id",
          "lane",
          "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"},
          "lane": {"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.12 workflow / secret 名稱 owner response 流程的脫敏 audit metadata；此欄位只是模板，尚未代表 production ingestion、secret value collection、workflow / runner execution 或 primary readiness。",
      "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.12 workflow / secret name parity 時可參考的脫敏範例；只供 AwoooP 顯示，不代表收件、驗收、secret value collection、workflow / runner execution 或 primary 授權。",
      "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_collection_checks": {
      "type": "array",
      "description": "AwoooP 顯示 S4.12 request packet 到收回 workflow / secret name owner response 之間的只讀收件檢查；不得把 request ready、audit template、redaction example 或 owner wording 誤判為 response received / accepted、secret value collection 或 workflow / runner 授權。",
      "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.12 workflow / secret 名稱 owner response 前後可執行的只讀 preflight；只分類可收、補證、隔離或拒收，不授權 secret value collection、workflow/webhook/runner/deploy key/branch protection/secret 修改或 primary 執行。",
      "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
    },
    "owner_response_request_packet": {
      "type": "object",
      "description": "AwoooP 可直接顯示給 owner 的 S4.12 workflow / secret 名稱回覆請求；只說明要填什麼與不得貼什麼，不授權收集 secret value、使用 write token、修改 workflow/webhook/runner/deploy key/branch protection/secret 或切換 GitHub primary。",
      "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
    },
    "response_templates": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "template_id",
          "lane",
          "affected_repos",
          "risk",
          "covered_repo_count",
          "requested_owner_decision",
          "required_owner_fields",
          "acceptable_decisions",
          "minimum_evidence_refs",
          "acceptance_criteria",
          "rejection_conditions",
          "allowed_outputs",
          "execution_authorized"
        ],
        "properties": {
          "template_id": {"type": "string"},
          "lane": {"type": "string"},
          "affected_repos": {
            "type": "array",
            "items": {"type": "string"},
            "minItems": 1
          },
          "risk": {"type": "string"},
          "covered_repo_count": {"type": "integer", "minimum": 0},
          "requested_owner_decision": {"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
    },
    "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
}
