{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:gitea-workflow-runner-health-v1",
  "title": "AWOOOI Gitea 工作流程與 runner 健康合約 v1",
  "description": "以 repo 內 committed Gitea workflow 與 runner guard script 建立只讀健康合約；不修改 workflow、不重啟 runner、不停止容器、不讀 Secret payload、不送 Telegram 測試通知。",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "program_status",
    "source_refs",
    "rollups",
    "workflow_records",
    "runner_contracts",
    "notification_contracts",
    "latest_observations",
    "operator_contract",
    "operation_boundaries",
    "approval_boundaries"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "gitea_workflow_runner_health_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"
      ],
      "properties": {
        "overall_completion_percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "current_priority": {
          "type": "string",
          "enum": [
            "P0",
            "P1",
            "P2",
            "P3"
          ]
        },
        "current_task_id": {
          "type": "string",
          "minLength": 1
        },
        "next_task_id": {
          "type": "string",
          "minLength": 1
        },
        "read_only_mode": {
          "type": "boolean",
          "const": true
        }
      },
      "additionalProperties": false
    },
    "source_refs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "rollups": {
      "type": "object",
      "additionalProperties": true
    },
    "workflow_records": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/workflow_record"
      }
    },
    "runner_contracts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/runner_contract"
      }
    },
    "notification_contracts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/notification_contract"
      }
    },
    "latest_observations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/observation"
      }
    },
    "operator_contract": {
      "type": "object",
      "additionalProperties": true
    },
    "operation_boundaries": {
      "type": "object",
      "additionalProperties": {
        "type": "boolean"
      }
    },
    "approval_boundaries": {
      "type": "object",
      "additionalProperties": {
        "type": "boolean",
        "const": false
      }
    }
  },
  "$defs": {
    "workflow_record": {
      "type": "object",
      "required": [
        "workflow_id",
        "file_ref",
        "display_name",
        "scope",
        "status",
        "risk_level",
        "triggers",
        "schedule_cadence",
        "runner_labels",
        "runner_evidence_status",
        "job_count",
        "notification_policy",
        "notify_bridge_calls",
        "secrets_policy_status",
        "evidence_refs",
        "next_action"
      ],
      "properties": {
        "workflow_id": {
          "type": "string",
          "minLength": 1
        },
        "file_ref": {
          "type": "string",
          "minLength": 1
        },
        "display_name": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "enum": [
            "manifest_mapped",
            "action_required",
            "blocked"
          ]
        },
        "risk_level": {
          "type": "string",
          "enum": [
            "low",
            "medium",
            "high",
            "critical"
          ]
        },
        "triggers": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "schedule_cadence": {
          "type": "string",
          "minLength": 1
        },
        "runner_labels": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "runner_evidence_status": {
          "type": "string",
          "enum": [
            "host_runner_mapped",
            "owner_attestation_required",
            "comment_ambiguous"
          ]
        },
        "job_count": {
          "type": "integer",
          "minimum": 1
        },
        "notification_policy": {
          "type": "string",
          "minLength": 1
        },
        "notify_bridge_calls": {
          "type": "integer",
          "minimum": 0
        },
        "secrets_policy_status": {
          "type": "string",
          "minLength": 1
        },
        "evidence_refs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "next_action": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "runner_contract": {
      "type": "object",
      "required": [
        "contract_id",
        "display_name",
        "status",
        "risk_level",
        "runner_labels",
        "used_by_workflows",
        "health_contract",
        "guardrail_refs",
        "evidence_refs",
        "next_action"
      ],
      "properties": {
        "contract_id": {
          "type": "string",
          "minLength": 1
        },
        "display_name": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "enum": [
            "manifest_mapped",
            "action_required",
            "dry_run_only",
            "prepared_not_applied_by_snapshot"
          ]
        },
        "risk_level": {
          "type": "string",
          "enum": [
            "low",
            "medium",
            "high",
            "critical"
          ]
        },
        "runner_labels": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "used_by_workflows": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "health_contract": {
          "type": "string",
          "minLength": 1
        },
        "guardrail_refs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "evidence_refs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "next_action": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "notification_contract": {
      "type": "object",
      "required": [
        "contract_id",
        "display_name",
        "status",
        "policy_kind",
        "success_noise_policy",
        "failure_policy",
        "workflow_refs",
        "evidence_refs",
        "next_action"
      ],
      "properties": {
        "contract_id": {
          "type": "string",
          "minLength": 1
        },
        "display_name": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "enum": [
            "preserved",
            "exception_documented",
            "action_required"
          ]
        },
        "policy_kind": {
          "type": "string",
          "enum": [
            "failure_only",
            "actionable_only",
            "deployment_status_exception",
            "manual_status_exception",
            "read_only_no_notify"
          ]
        },
        "success_noise_policy": {
          "type": "string",
          "minLength": 1
        },
        "failure_policy": {
          "type": "string",
          "minLength": 1
        },
        "workflow_refs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "evidence_refs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "next_action": {
          "type": "string",
          "minLength": 1
        }
      },
      "additionalProperties": false
    },
    "observation": {
      "type": "object",
      "required": [
        "observation_id",
        "status",
        "summary",
        "evidence_refs"
      ],
      "properties": {
        "observation_id": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "type": "string",
          "enum": [
            "verified",
            "action_required",
            "not_applicable"
          ]
        },
        "summary": {
          "type": "string",
          "minLength": 1
        },
        "evidence_refs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
