{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:product-code-review-gate-v1",
  "title": "AWOOOI product code review gate v1",
  "description": "全產品推版前後 Code Review / 防木馬 Gate 只讀讀回。此 schema 不授權外部 scanner 啟用、workflow 寫入、auto merge、production deploy、Aider 自動 patch、secret 讀取、host probe、registry push、artifact signing、Telegram 實發或 Gateway queue write。",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "program_status",
    "source_refs",
    "rollups",
    "pre_deploy_gates",
    "post_deploy_gates",
    "ai_reviewer_lanes",
    "mainstream_tool_lanes",
    "decision_matrix",
    "gate_boundaries",
    "next_actions"
  ],
  "properties": {
    "schema_version": { "type": "string", "const": "product_code_review_gate_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", "minimum": 0, "maximum": 100 },
        "current_priority": { "type": "string", "enum": ["P0", "P1", "P2", "P3"] },
        "current_task_id": { "type": "string", "const": "P2-111" },
        "next_task_id": { "type": "string", "minLength": 1 },
        "read_only_mode": { "type": "boolean", "const": true },
        "runtime_authority": { "type": "string", "minLength": 1 },
        "status_note": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "source_refs": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string", "minLength": 1 }
    },
    "rollups": {
      "type": "object",
      "required": [
        "product_scope_count",
        "public_route_count_minimum",
        "source_candidate_repo_count",
        "pre_deploy_gate_count",
        "post_deploy_gate_count",
        "ai_reviewer_count",
        "mainstream_tool_count",
        "owner_review_required_count",
        "critical_gap_count",
        "blocked_operation_count",
        "active_write_gate_count",
        "action_button_count"
      ],
      "additionalProperties": { "type": "integer" }
    },
    "pre_deploy_gates": { "$ref": "#/$defs/gateArray" },
    "post_deploy_gates": { "$ref": "#/$defs/gateArray" },
    "ai_reviewer_lanes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["agent_id", "label", "role", "allowed_output", "write_allowed"],
        "properties": {
          "agent_id": { "type": "string", "minLength": 1 },
          "label": { "type": "string", "minLength": 1 },
          "role": { "type": "string", "minLength": 1 },
          "allowed_output": { "type": "string", "minLength": 1 },
          "write_allowed": { "type": "boolean", "const": false }
        },
        "additionalProperties": false
      }
    },
    "mainstream_tool_lanes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "tool_id",
          "label",
          "category",
          "source_url",
          "integration_status",
          "recommended_role",
          "blocked_now"
        ],
        "properties": {
          "tool_id": { "type": "string", "minLength": 1 },
          "label": { "type": "string", "minLength": 1 },
          "category": { "type": "string", "minLength": 1 },
          "source_url": { "type": "string", "minLength": 1 },
          "integration_status": { "type": "string", "minLength": 1 },
          "recommended_role": { "type": "string", "minLength": 1 },
          "blocked_now": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 }
          }
        },
        "additionalProperties": false
      }
    },
    "decision_matrix": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["risk_lane", "reviewer", "aider_role", "required_gate", "post_deploy"],
        "additionalProperties": { "type": "string" }
      }
    },
    "gate_boundaries": {
      "type": "object",
      "required": ["read_only_api_allowed"],
      "additionalProperties": { "type": "boolean" }
    },
    "next_actions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["task_id", "priority", "summary", "gate"],
        "additionalProperties": { "type": "string" }
      }
    }
  },
  "$defs": {
    "gateArray": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "gate_id",
          "label",
          "coverage",
          "status",
          "owner_agent",
          "evidence_refs",
          "current_gap",
          "next_action"
        ],
        "properties": {
          "gate_id": { "type": "string", "minLength": 1 },
          "label": { "type": "string", "minLength": 1 },
          "coverage": { "type": "string", "minLength": 1 },
          "status": { "type": "string", "minLength": 1 },
          "owner_agent": { "type": "string", "minLength": 1 },
          "evidence_refs": {
            "type": "array",
            "minItems": 1,
            "items": { "type": "string", "minLength": 1 }
          },
          "current_gap": { "type": "string", "minLength": 1 },
          "next_action": { "type": "string", "minLength": 1 }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": true
}
