{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/diff-risk.schema.json",
  "version": "1.1.0",
  "title": "Multi-Agent Pipeline  -  Phase 4 diff risk score",
  "description": "Output contract for diff-risk-score.mjs. Heuristic, deterministic, no LLM. Produced before Phase 4 Step 2 to give reviewer prompts a priority ordering  -  never used as a gate. v1.1.0 adds the test_lines_removed signal (immutable-test backstop: a test file whose diff removes more lines than it adds).",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "task", "totals", "files"],
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "1.1.0"
    },
    "task": {
      "type": "object",
      "additionalProperties": false,
      "required": ["base", "head"],
      "properties": {
        "id": { "type": ["string", "null"] },
        "base": { "type": "string", "description": "Base ref (e.g. origin/main)." },
        "head": { "type": "string", "description": "Head ref (e.g. HEAD or branch name)." },
        "ts": { "type": "string", "format": "date-time" }
      }
    },
    "totals": {
      "type": "object",
      "additionalProperties": false,
      "required": ["files", "loc_added", "loc_removed", "max_score"],
      "properties": {
        "files": { "type": "integer", "minimum": 0 },
        "loc_added": { "type": "integer", "minimum": 0 },
        "loc_removed": { "type": "integer", "minimum": 0 },
        "max_score": { "type": "number", "minimum": 0 }
      }
    },
    "files": {
      "type": "array",
      "description": "One entry per changed file, sorted by score descending. Top-N (caller-controlled, default 5) feeds the reviewer priority hint.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "score", "loc_added", "loc_removed", "signals"],
        "properties": {
          "path": { "type": "string", "minLength": 1 },
          "score": { "type": "number", "minimum": 0 },
          "loc_added": { "type": "integer", "minimum": 0 },
          "loc_removed": { "type": "integer", "minimum": 0 },
          "signals": {
            "type": "array",
            "description": "Heuristic signals that contributed to the score. Each entry is a {name, weight, value} triple  -  name is the rule id (e.g. 'security_path'), weight is its multiplier from rules table, value is the rule's evaluated quantity (loc, count, 1 for booleans).",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["name", "weight", "value"],
              "properties": {
                "name": {
                  "type": "string",
                  "enum": [
                    "loc_changed",
                    "security_path",
                    "public_api",
                    "no_test_change",
                    "complexity_delta",
                    "ui_critical",
                    "migration",
                    "test_lines_removed"
                  ]
                },
                "weight": { "type": "number" },
                "value": { "type": "number" }
              }
            }
          }
        }
      }
    }
  }
}
