{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mere.run/contracts/graph-node-event.v1.schema.json",
  "title": "mere.run Plugin Graph Node Event v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["contract_version", "sequence", "created_at", "type"],
  "properties": {
    "contract_version": {"const": "mere.run/plugin-graph-event.v1"},
    "sequence": {"type": "integer", "minimum": 0},
    "created_at": {"type": "string", "format": "date-time"},
    "type": {"enum": ["progress", "preview_ready", "artifact_ready", "diagnostic", "metric", "heartbeat", "node_result"]},
    "message": {"type": "string"},
    "progress": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "phase": {"type": "string"},
        "current": {"type": "number", "minimum": 0},
        "total": {"type": "number", "exclusiveMinimum": 0},
        "fraction": {"type": "number", "minimum": 0, "maximum": 1},
        "unit": {"type": "string"}
      }
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "path", "content_type"],
      "properties": {
        "name": {"type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$"},
        "path": {"type": "string", "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$)).+$"},
        "content_type": {"type": "string", "minLength": 1}
      }
    },
    "diagnostic": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "severity", "title", "message"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z][a-z0-9_-]{0,127}$"},
        "severity": {"enum": ["info", "warning", "blocker"]},
        "title": {"type": "string"},
        "message": {"type": "string"}
      }
    },
    "metric": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "value"],
      "properties": {
        "name": {"type": "string", "minLength": 1},
        "value": {"type": "number"},
        "unit": {"type": "string"}
      }
    },
    "outputs": {"type": "object", "additionalProperties": {"$ref": "#/$defs/value"}}
  },
  "$defs": {
    "value": {
      "anyOf": [
        {"type": "null"},
        {"type": "string"},
        {"type": "integer"},
        {"type": "number"},
        {"type": "boolean"},
        {"type": "array", "items": {"$ref": "#/$defs/value"}},
        {"type": "object", "additionalProperties": {"$ref": "#/$defs/value"}}
      ]
    }
  }
}
