{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://awoooi.wooo.work/schemas/ai_agent_live_read_model_gate_v1.schema.json",
  "title": "AI Agent Live Read Model Gate v1",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "program_status",
    "source_refs",
    "live_truth",
    "existing_storage_contract",
    "redis_stream_contract",
    "read_model_cards",
    "worker_gate_plan",
    "rollback_plan",
    "no_write_smoke_plan",
    "display_redaction_contract",
    "approval_boundaries",
    "rollups"
  ],
  "properties": {
    "schema_version": {
      "const": "ai_agent_live_read_model_gate_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"
      ],
      "properties": {
        "overall_completion_percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "current_priority": {
          "type": "string"
        },
        "current_task_id": {
          "type": "string"
        },
        "next_task_id": {
          "type": "string"
        },
        "read_only_mode": {
          "const": true
        },
        "runtime_authority": {
          "const": "gate_plan_only_no_live_worker"
        }
      },
      "additionalProperties": true
    },
    "source_refs": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "live_truth": {
      "type": "object",
      "required": [
        "live_agent_session_readback_enabled",
        "live_redis_stream_read_enabled",
        "runtime_worker_enabled",
        "telegram_receipt_send_enabled",
        "learning_writeback_enabled",
        "active_live_agent_sessions",
        "live_redis_events_24h",
        "live_handoffs_24h",
        "live_learning_writes_24h",
        "telegram_digest_receipts_24h"
      ],
      "properties": {
        "live_agent_session_readback_enabled": {
          "const": false
        },
        "live_redis_stream_read_enabled": {
          "const": false
        },
        "runtime_worker_enabled": {
          "const": false
        },
        "telegram_receipt_send_enabled": {
          "const": false
        },
        "learning_writeback_enabled": {
          "const": false
        },
        "active_live_agent_sessions": {
          "const": 0
        },
        "live_redis_events_24h": {
          "const": 0
        },
        "live_handoffs_24h": {
          "const": 0
        },
        "live_learning_writes_24h": {
          "const": 0
        },
        "telegram_digest_receipts_24h": {
          "const": 0
        }
      },
      "additionalProperties": true
    },
    "existing_storage_contract": {
      "type": "object",
      "required": [
        "db_table",
        "schema_status",
        "migration_delta_required",
        "approved_for_live_query",
        "safe_read_query_defined",
        "safe_selected_fields",
        "forbidden_selected_fields",
        "required_indexes",
        "read_query_contract"
      ],
      "properties": {
        "db_table": {
          "const": "agent_sessions"
        },
        "migration_delta_required": {
          "const": false
        },
        "approved_for_live_query": {
          "const": false
        },
        "safe_read_query_defined": {
          "const": true
        },
        "safe_selected_fields": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        },
        "forbidden_selected_fields": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        },
        "required_indexes": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        }
      },
      "additionalProperties": true
    },
    "redis_stream_contract": {
      "type": "object",
      "required": [
        "stream_namespace",
        "candidate_streams",
        "consumer_group_allowed",
        "xadd_allowed",
        "xreadgroup_allowed",
        "event_envelope_required_fields"
      ],
      "properties": {
        "consumer_group_allowed": {
          "const": false
        },
        "xadd_allowed": {
          "const": false
        },
        "xreadgroup_allowed": {
          "const": false
        },
        "event_envelope_required_fields": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        }
      },
      "additionalProperties": true
    },
    "read_model_cards": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/read_model_card"
      },
      "minItems": 1
    },
    "worker_gate_plan": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/worker_gate"
      },
      "minItems": 1
    },
    "rollback_plan": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/rollback_step"
      },
      "minItems": 1
    },
    "no_write_smoke_plan": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/no_write_smoke"
      },
      "minItems": 1
    },
    "display_redaction_contract": {
      "type": "object",
      "required": [
        "redaction_required",
        "work_window_conversation_display_allowed",
        "agent_raw_output_display_allowed",
        "secret_value_display_allowed",
        "forbidden_frontend_content"
      ],
      "properties": {
        "redaction_required": {
          "const": true
        },
        "work_window_conversation_display_allowed": {
          "const": false
        },
        "agent_raw_output_display_allowed": {
          "const": false
        },
        "secret_value_display_allowed": {
          "const": false
        },
        "forbidden_frontend_content": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        }
      },
      "additionalProperties": true
    },
    "approval_boundaries": {
      "type": "object",
      "required": [
        "db_migration_allowed",
        "live_db_query_allowed",
        "redis_xadd_allowed",
        "redis_consumer_group_allowed",
        "runtime_worker_allowed",
        "telegram_direct_send_allowed",
        "learning_writeback_allowed",
        "secret_plaintext_allowed",
        "conversation_transcript_display_allowed",
        "private_reasoning_display_allowed",
        "agent_raw_output_display_allowed"
      ],
      "properties": {
        "db_migration_allowed": {
          "const": false
        },
        "live_db_query_allowed": {
          "const": false
        },
        "redis_xadd_allowed": {
          "const": false
        },
        "redis_consumer_group_allowed": {
          "const": false
        },
        "runtime_worker_allowed": {
          "const": false
        },
        "telegram_direct_send_allowed": {
          "const": false
        },
        "learning_writeback_allowed": {
          "const": false
        },
        "secret_plaintext_allowed": {
          "const": false
        },
        "conversation_transcript_display_allowed": {
          "const": false
        },
        "private_reasoning_display_allowed": {
          "const": false
        },
        "agent_raw_output_display_allowed": {
          "const": false
        }
      },
      "additionalProperties": false
    },
    "rollups": {
      "type": "object",
      "required": [
        "source_ref_count",
        "read_model_card_count",
        "gate_count",
        "approval_required_gate_ids",
        "query_contract_ready_card_ids",
        "rollback_step_count",
        "no_write_smoke_count",
        "forbidden_frontend_content_count",
        "live_truth_count_total"
      ],
      "properties": {
        "live_truth_count_total": {
          "const": 0
        }
      },
      "additionalProperties": true
    }
  },
  "$defs": {
    "read_model_card": {
      "type": "object",
      "required": [
        "card_id",
        "display_name",
        "owner_agent",
        "source_of_truth",
        "readiness_status",
        "operator_signal",
        "next_gate"
      ],
      "additionalProperties": true
    },
    "worker_gate": {
      "type": "object",
      "required": [
        "gate_id",
        "display_name",
        "owner_agent",
        "status",
        "required_evidence",
        "blocked_action"
      ],
      "additionalProperties": true
    },
    "rollback_step": {
      "type": "object",
      "required": [
        "rollback_id",
        "step",
        "owner_agent"
      ],
      "additionalProperties": true
    },
    "no_write_smoke": {
      "type": "object",
      "required": [
        "smoke_id",
        "status",
        "writes_allowed",
        "assertion"
      ],
      "properties": {
        "status": {
          "const": "defined"
        },
        "writes_allowed": {
          "const": false
        }
      },
      "additionalProperties": true
    }
  }
}
