{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:s4-9-owner-response-gap-audit-v1",
  "title": "S4.9 Owner Response Gap Audit v1",
  "description": "S4.9 owner response gate 的只讀缺口稽核。此 schema 僅允許記錄不符合項、需新增規範、需調整規範與優先工作佇列，不授權 request dispatch、owner response accepted、repo / refs / workflow / secret / runtime action。",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "git_commit",
    "status",
    "mode",
    "basis",
    "summary",
    "false_boundaries",
    "public_surface_redaction_requirements",
    "current_requirement_gaps",
    "new_rules_required",
    "rule_adjustments_required",
    "priority_work_queue",
    "next_safe_actions"
  ],
  "properties": {
    "schema_version": {
      "const": "s4_9_owner_response_gap_audit_v1"
    },
    "generated_at": {
      "type": "string"
    },
    "git_commit": {
      "type": "string"
    },
    "status": {
      "const": "gap_audit_ready_owner_gate_zero"
    },
    "mode": {
      "const": "read_only_gap_audit_no_runtime_action"
    },
    "basis": {
      "type": "object",
      "required": [
        "gitea_main_commit",
        "latest_runtime_deploy_marker",
        "latest_tenants_redaction_commit",
        "latest_logbook_commit",
        "source_control_rollup_date",
        "source_control_rollup_templates",
        "production_verification_required_for_frontend_changes"
      ],
      "properties": {
        "gitea_main_commit": {"type": "string"},
        "latest_runtime_deploy_marker": {"type": "string"},
        "latest_tenants_redaction_commit": {"type": "string"},
        "latest_logbook_commit": {"type": "string"},
        "source_control_rollup_date": {"type": "string"},
        "source_control_rollup_templates": {"type": "integer"},
        "production_verification_required_for_frontend_changes": {"type": "boolean", "const": true}
      },
      "additionalProperties": false
    },
    "summary": {
      "type": "object",
      "required": [
        "current_requirement_gap_count",
        "active_blocker_count",
        "active_risk_or_process_gap_count",
        "mitigated_needs_guard_count",
        "new_rule_count",
        "rule_adjustment_count",
        "priority_work_item_count",
        "s4_9_owner_response_gate_percent",
        "request_sent_count",
        "owner_response_received_count",
        "owner_response_accepted_count",
        "owner_response_rejected_count",
        "runtime_gate_count",
        "public_surface_redaction_guard_ready",
        "public_surface_raw_namespace_allowed",
        "work_session_transcript_public_allowed"
      ],
      "properties": {
        "current_requirement_gap_count": {"type": "integer", "minimum": 1},
        "active_blocker_count": {"type": "integer", "minimum": 0},
        "active_risk_or_process_gap_count": {"type": "integer", "minimum": 0},
        "mitigated_needs_guard_count": {"type": "integer", "minimum": 0},
        "new_rule_count": {"type": "integer", "minimum": 1},
        "rule_adjustment_count": {"type": "integer", "minimum": 1},
        "priority_work_item_count": {"type": "integer", "minimum": 1},
        "s4_9_owner_response_gate_percent": {"type": "integer", "const": 0},
        "request_sent_count": {"type": "integer", "const": 0},
        "owner_response_received_count": {"type": "integer", "const": 0},
        "owner_response_accepted_count": {"type": "integer", "const": 0},
        "owner_response_rejected_count": {"type": "integer", "const": 0},
        "runtime_gate_count": {"type": "integer", "const": 0},
        "public_surface_redaction_guard_ready": {"type": "boolean", "const": true},
        "public_surface_raw_namespace_allowed": {"type": "boolean", "const": false},
        "work_session_transcript_public_allowed": {"type": "boolean", "const": false}
      },
      "additionalProperties": false
    },
    "false_boundaries": {
      "type": "object",
      "additionalProperties": {"type": "boolean", "const": false},
      "minProperties": 1
    },
    "public_surface_redaction_requirements": {
      "type": "object",
      "required": [
        "allowed_display",
        "forbidden_display",
        "required_fields_or_markers",
        "verification"
      ],
      "properties": {
        "allowed_display": {"type": "array", "items": {"type": "string"}, "minItems": 1},
        "forbidden_display": {"type": "array", "items": {"type": "string"}, "minItems": 1},
        "required_fields_or_markers": {"type": "array", "items": {"type": "string"}, "minItems": 1},
        "verification": {"type": "array", "items": {"type": "string"}, "minItems": 1}
      },
      "additionalProperties": false
    },
    "current_requirement_gaps": {
      "type": "array",
      "items": {"$ref": "#/$defs/gap_item"},
      "minItems": 1
    },
    "new_rules_required": {
      "type": "array",
      "items": {"$ref": "#/$defs/rule_item"},
      "minItems": 1
    },
    "rule_adjustments_required": {
      "type": "array",
      "items": {"$ref": "#/$defs/adjustment_item"},
      "minItems": 1
    },
    "priority_work_queue": {
      "type": "array",
      "items": {"$ref": "#/$defs/work_item"},
      "minItems": 1
    },
    "next_safe_actions": {
      "type": "array",
      "items": {"type": "string"},
      "minItems": 1
    }
  },
  "$defs": {
    "gap_item": {
      "type": "object",
      "required": ["gap_id", "priority", "status", "requirement", "current_state", "required_next_step"],
      "properties": {
        "gap_id": {"type": "string"},
        "priority": {"type": "string"},
        "status": {"type": "string"},
        "requirement": {"type": "string"},
        "current_state": {"type": "string"},
        "required_next_step": {"type": "string"}
      },
      "additionalProperties": false
    },
    "rule_item": {
      "type": "object",
      "required": ["rule_id", "priority", "rule", "verification"],
      "properties": {
        "rule_id": {"type": "string"},
        "priority": {"type": "string"},
        "rule": {"type": "string"},
        "verification": {"type": "string"}
      },
      "additionalProperties": false
    },
    "adjustment_item": {
      "type": "object",
      "required": ["adjustment_id", "priority", "from_rule", "adjusted_rule"],
      "properties": {
        "adjustment_id": {"type": "string"},
        "priority": {"type": "string"},
        "from_rule": {"type": "string"},
        "adjusted_rule": {"type": "string"}
      },
      "additionalProperties": false
    },
    "work_item": {
      "type": "object",
      "required": ["priority", "work_item", "completion_percent", "blocked_by", "next_validation"],
      "properties": {
        "priority": {"type": "string"},
        "work_item": {"type": "string"},
        "completion_percent": {"type": "integer", "minimum": 0, "maximum": 100},
        "blocked_by": {"type": "string"},
        "next_validation": {"type": "string"}
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
