{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://awoooi.local/schemas/ai_agent_runtime_write_gate_review_v1.schema.json",
  "title": "AI Agent Runtime Write Gate Review",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "program_status",
    "source_refs",
    "runtime_write_truth",
    "write_gate_review",
    "write_targets",
    "approval_gates",
    "post_write_verification",
    "approval_boundaries",
    "display_redaction_contract",
    "rollups"
  ],
  "properties": {
    "schema_version": { "const": "ai_agent_runtime_write_gate_review_v1" },
    "generated_at": { "type": "string" },
    "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": { "enum": ["P0", "P1", "P2", "P3"] },
        "current_task_id": { "const": "P2-403G" },
        "next_task_id": { "const": "P2-403H" },
        "read_only_mode": { "const": true },
        "runtime_authority": { "const": "write_gate_review_only_no_runtime_write" },
        "status_note": { "type": "string" }
      },
      "additionalProperties": false
    },
    "source_refs": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
    "runtime_write_truth": {
      "type": "object",
      "required": [
        "runtime_write_allowed",
        "dual_approval_required",
        "dual_approval_received_count",
        "dry_run_hash_required",
        "dry_run_hash_verified_count",
        "post_write_verifier_required",
        "post_write_verifier_pass_count",
        "km_write_allowed",
        "playbook_trust_write_allowed",
        "timeline_learning_write_allowed",
        "agent_replay_score_write_allowed",
        "telegram_send_allowed",
        "truth_note"
      ],
      "properties": {
        "runtime_write_allowed": { "const": false },
        "dual_approval_required": { "const": true },
        "dual_approval_received_count": { "const": 0 },
        "dry_run_hash_required": { "const": true },
        "dry_run_hash_verified_count": { "const": 0 },
        "post_write_verifier_required": { "const": true },
        "post_write_verifier_pass_count": { "const": 0 },
        "km_write_allowed": { "const": false },
        "playbook_trust_write_allowed": { "const": false },
        "timeline_learning_write_allowed": { "const": false },
        "agent_replay_score_write_allowed": { "const": false },
        "telegram_send_allowed": { "const": false },
        "truth_note": { "type": "string" }
      },
      "additionalProperties": false
    },
    "write_gate_review": {
      "type": "object",
      "required": ["required_fields", "forbidden_fields", "operator_meaning"],
      "properties": {
        "required_fields": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "forbidden_fields": { "type": "array", "items": { "type": "string" }, "minItems": 1 },
        "operator_meaning": { "type": "string" }
      },
      "additionalProperties": false
    },
    "write_targets": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["target_id", "display_name", "status", "owner_agent", "required_before_write", "blocked_write_action"],
        "properties": {
          "target_id": { "type": "string" },
          "display_name": { "type": "string" },
          "status": { "enum": ["approval_required", "blocked_by_runtime_gate", "contract_ready"] },
          "owner_agent": { "enum": ["openclaw", "hermes", "nemotron"] },
          "required_before_write": { "type": "string" },
          "blocked_write_action": { "type": "string" }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "approval_gates": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["gate_id", "display_name", "status", "required_evidence", "blocked_runtime_action"],
        "properties": {
          "gate_id": { "type": "string" },
          "display_name": { "type": "string" },
          "status": { "enum": ["approval_required", "blocked_by_runtime_gate", "contract_ready"] },
          "required_evidence": { "type": "string" },
          "blocked_runtime_action": { "type": "string" }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "post_write_verification": {
      "type": "object",
      "required": ["verification_required", "rollback_required", "verification_steps"],
      "properties": {
        "verification_required": { "const": true },
        "rollback_required": { "const": true },
        "verification_steps": { "type": "array", "items": { "type": "string" }, "minItems": 1 }
      },
      "additionalProperties": false
    },
    "approval_boundaries": {
      "type": "object",
      "additionalProperties": { "const": false }
    },
    "display_redaction_contract": {
      "type": "object",
      "required": ["redaction_required", "raw_payload_display_allowed", "private_reasoning_display_allowed", "secret_value_display_allowed", "allowed_frontend_content", "forbidden_frontend_content", "frontend_display_policy"],
      "properties": {
        "redaction_required": { "const": true },
        "raw_payload_display_allowed": { "const": false },
        "private_reasoning_display_allowed": { "const": false },
        "secret_value_display_allowed": { "const": false },
        "allowed_frontend_content": { "type": "array", "items": { "type": "string" } },
        "forbidden_frontend_content": { "type": "array", "items": { "type": "string" } },
        "frontend_display_policy": { "type": "string" }
      },
      "additionalProperties": false
    },
    "rollups": {
      "type": "object",
      "required": ["write_target_count", "approval_gate_count", "approval_required_gate_ids", "blocked_runtime_action_count", "required_field_count", "forbidden_field_count", "live_write_count_total"],
      "properties": {
        "write_target_count": { "type": "integer", "minimum": 0 },
        "approval_gate_count": { "type": "integer", "minimum": 0 },
        "approval_required_gate_ids": { "type": "array", "items": { "type": "string" } },
        "blocked_runtime_action_count": { "type": "integer", "minimum": 0 },
        "required_field_count": { "type": "integer", "minimum": 0 },
        "forbidden_field_count": { "type": "integer", "minimum": 0 },
        "live_write_count_total": { "const": 0 }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
