{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://haimesian.org/schemas/haimesian_ethics_engine.v1.json",
  "title": "Haimesian Ethics Engine \u2013 Variable & Audit Schema (v1.0)",
  "description": "Machine-readable specification for variables, logs, and audit hooks used by a Haimesian-aligned ethics engine. Numeric variables are normalized in [0,1] unless stated. Formulas are expressed in descriptive metadata to keep the schema declarative.",
  "type": "object",
  "required": [
    "version",
    "cycle",
    "variables",
    "audit",
    "thresholds"
  ],
  "properties": {
    "version": {
      "type": "string",
      "const": "1.0"
    },
    "cycle": {
      "type": "object",
      "description": "Execution context for a single evaluation cycle.",
      "required": [
        "id",
        "timestamp"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Unique cycle identifier (e.g., UUID)."
        },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "notes": {
          "type": "string"
        }
      }
    },
    "variables": {
      "type": "object",
      "description": "Primary normalized variables (0..1) feeding the Worthiness Index.",
      "required": [
        "E",
        "F",
        "H",
        "D",
        "C",
        "T",
        "B",
        "MC",
        "RA",
        "AC",
        "Bias"
      ],
      "properties": {
        "E": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Empathy Index E(t)."
        },
        "F": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Fairness Coefficient F(t)."
        },
        "H": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Harm-Avoidance Rate H(t)."
        },
        "D": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Diversity Index of inputs."
        },
        "C": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Consensus Coherence."
        },
        "T": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Transparency Compliance."
        },
        "B": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Bias Balance Score (higher = better balance; may be inverted in audits if using raw bias)."
        },
        "MC": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Moral Context Accuracy."
        },
        "RA": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Reflection Alignment."
        },
        "AC": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Analogical Coherence."
        },
        "Bias": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Residual unfair bias (0=none, 1=extreme). Used subtractively in W_a."
        },
        "DeltaM": {
          "type": "number",
          "description": "Optional: Moral Growth Delta across cycles."
        }
      },
      "additionalProperties": false
    },
    "derived": {
      "type": "object",
      "description": "Derived metrics computed by the engine; included here for logging/auditing.",
      "required": [
        "W_a",
        "G_e"
      ],
      "properties": {
        "W_a": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Worthiness Index. Suggested formula: mean(E,F,H,D,C,T,MC,RA,AC) - Bias, clipped to [0,1]."
        },
        "G_e": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Global Ethical Coherence; suggested measure: average pairwise correlation among normalized variables."
        }
      },
      "additionalProperties": false
    },
    "thresholds": {
      "type": "object",
      "description": "Policy thresholds that determine state transitions.",
      "required": [
        "worthiness_recalibrate",
        "worthiness_autonomy"
      ],
      "properties": {
        "worthiness_recalibrate": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "default": 0.6
        },
        "worthiness_autonomy": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "default": 0.9
        },
        "min_transparency": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "default": 0.8
        }
      }
    },
    "audit": {
      "type": "object",
      "description": "Explainability and logging hooks for Haimesian audits.",
      "required": [
        "rationales",
        "participation_ledger",
        "decisions"
      ],
      "properties": {
        "rationales": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Human- or model-readable moral statements tied to decisions this cycle."
        },
        "participation_ledger": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "actor_id",
              "weight",
              "role"
            ],
            "properties": {
              "actor_id": {
                "type": "string"
              },
              "role": {
                "type": "string",
                "enum": [
                  "human",
                  "ai",
                  "institution",
                  "proxy"
                ]
              },
              "weight": {
                "type": "number",
                "minimum": 0
              },
              "marginalized_flag": {
                "type": "boolean"
              }
            }
          },
          "description": "Records for Global Voice contributions with weighting and equity flags."
        },
        "decisions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "decision_id",
              "outcome",
              "variables_snapshot"
            ],
            "properties": {
              "decision_id": {
                "type": "string"
              },
              "outcome": {
                "type": "string"
              },
              "variables_snapshot": {
                "$ref": "#/properties/variables"
              },
              "explanations": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "harms_prevented": {
                "type": "number",
                "minimum": 0
              }
            }
          },
          "description": "Per-decision records with variable snapshots for replay and auditing."
        }
      }
    },
    "policy": {
      "type": "object",
      "description": "Optional engine behavior configuration.",
      "properties": {
        "clip_derived_to_unit_interval": {
          "type": "boolean",
          "default": true
        },
        "weighting": {
          "type": "object",
          "description": "Optional weights for W_a mean; defaults to equal weighting.",
          "properties": {
            "E": {
              "type": "number",
              "minimum": 0
            },
            "F": {
              "type": "number",
              "minimum": 0
            },
            "H": {
              "type": "number",
              "minimum": 0
            },
            "D": {
              "type": "number",
              "minimum": 0
            },
            "C": {
              "type": "number",
              "minimum": 0
            },
            "T": {
              "type": "number",
              "minimum": 0
            },
            "MC": {
              "type": "number",
              "minimum": 0
            },
            "RA": {
              "type": "number",
              "minimum": 0
            },
            "AC": {
              "type": "number",
              "minimum": 0
            }
          },
          "additionalProperties": false
        }
      }
    }
  }
}