{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "audit_results.schema.json",
  "title": "Audit Results",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "task_id": {
        "type": "string"
      },
      "unit_id": {
        "type": "string"
      },
      "pass_id": {
        "type": "string"
      },
      "lens": {
        "type": "string",
        "enum": [
          "correctness",
          "architecture",
          "maintainability",
          "security",
          "reliability",
          "performance",
          "data_integrity",
          "tests",
          "operability",
          "config_deployment",
          "observability"
        ]
      },
      "agent_role": {
        "type": "string"
      },
      "file_coverage": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "path": {
              "type": "string"
            },
            "total_lines": {
              "type": "integer",
              "minimum": 0
            },
            "reviewed_lines": {
              "type": "integer",
              "minimum": 0
            }
          },
          "required": [
            "path",
            "total_lines"
          ],
          "additionalProperties": false
        },
        "minItems": 1
      },
      "findings": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "title": {
              "type": "string"
            },
            "category": {
              "type": "string",
              "minLength": 1
            },
            "severity": {
              "type": "string",
              "enum": [
                "critical",
                "high",
                "medium",
                "low",
                "info"
              ]
            },
            "confidence": {
              "type": "string",
              "enum": [
                "high",
                "medium",
                "low"
              ]
            },
            "lens": {
              "type": "string",
              "enum": [
                "correctness",
                "architecture",
                "maintainability",
                "security",
                "reliability",
                "performance",
                "data_integrity",
                "tests",
                "operability",
                "config_deployment",
                "observability"
              ],
              "description": "defaults from the enclosing AuditResult lens when omitted."
            },
            "summary": {
              "type": "string"
            },
            "affected_files": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "path": {
                    "type": "string"
                  },
                  "line_start": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "line_end": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "symbol": {
                    "type": "string"
                  },
                  "quoted_text": {
                    "type": "string"
                  },
                  "hash_at_plan_time": {
                    "type": "string"
                  }
                },
                "required": [
                  "path"
                ],
                "additionalProperties": false
              },
              "minItems": 1
            },
            "impact": {
              "type": "string"
            },
            "likelihood": {
              "type": "string"
            },
            "evidence": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            },
            "reproduction": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            },
            "systemic": {
              "type": "boolean"
            },
            "related_findings": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1
            },
            "theme_id": {
              "type": "string"
            },
            "blast_radius": {
              "type": "integer",
              "minimum": 0
            },
            "evidence_grounded": {
              "type": "boolean"
            },
            "executable_anchor": {
              "type": "object",
              "properties": {
                "command": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "minItems": 1
                },
                "confirm_if": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "exit_zero"
                        }
                      },
                      "required": [
                        "kind"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "exit_nonzero"
                        }
                      },
                      "required": [
                        "kind"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "output_includes"
                        },
                        "text": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "kind",
                        "text"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "kind": {
                          "type": "string",
                          "const": "output_excludes"
                        },
                        "text": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "kind",
                        "text"
                      ],
                      "additionalProperties": false
                    }
                  ]
                },
                "claim": {
                  "type": "string"
                }
              },
              "required": [
                "command",
                "confirm_if"
              ],
              "additionalProperties": false
            },
            "contract_goal_id": {
              "type": "string"
            },
            "contract_obligation_ids": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "verification_obligation_ids": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "targeted_commands": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "analyzer_provenance": {
              "type": "object",
              "properties": {
                "analyzer_id": {
                  "type": "string"
                },
                "rule": {
                  "type": "string"
                },
                "path": {
                  "type": "string"
                },
                "snippet_hash": {
                  "type": "string"
                }
              },
              "required": [
                "analyzer_id",
                "path",
                "snippet_hash"
              ],
              "additionalProperties": false,
              "description": "Content-anchored identity of the analyzer lead this finding was born from. Copy it VERBATIM from the injected lead's provenance object; omit for findings not born from an analyzer lead."
            }
          },
          "required": [
            "id",
            "title",
            "category",
            "severity",
            "confidence",
            "summary",
            "affected_files",
            "evidence"
          ],
          "additionalProperties": false
        }
      },
      "reviewed_clean": {
        "type": "boolean"
      },
      "notes": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "requires_followup": {
        "type": "boolean"
      },
      "followup_tasks": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "verification": {
        "type": "object",
        "properties": {
          "verified": {
            "type": "boolean"
          },
          "needs_followup": {
            "type": "boolean"
          },
          "concerns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "coverage_concerns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "confidence_concerns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "followup_tasks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "task_id": {
                  "type": "string"
                },
                "unit_id": {
                  "type": "string"
                },
                "pass_id": {
                  "type": "string"
                },
                "lens": {
                  "type": "string",
                  "enum": [
                    "correctness",
                    "architecture",
                    "maintainability",
                    "security",
                    "reliability",
                    "performance",
                    "data_integrity",
                    "tests",
                    "operability",
                    "config_deployment",
                    "observability"
                  ]
                },
                "file_paths": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "minItems": 1
                },
                "file_line_counts": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "integer",
                    "minimum": 0
                  }
                },
                "line_ranges": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "path": {
                        "type": "string"
                      },
                      "start": {
                        "type": "integer",
                        "minimum": 1
                      },
                      "end": {
                        "type": "integer",
                        "minimum": 1
                      }
                    },
                    "required": [
                      "path",
                      "start",
                      "end"
                    ],
                    "additionalProperties": false
                  }
                },
                "inputs": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                },
                "rationale": {
                  "type": "string"
                },
                "priority": {
                  "type": "string",
                  "enum": [
                    "high",
                    "medium",
                    "low"
                  ]
                },
                "token_estimate": {
                  "type": "number",
                  "minimum": 0
                },
                "risk_estimate": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "tags": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "minItems": 1
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "pending",
                    "complete"
                  ]
                },
                "completed_at": {
                  "type": "string"
                },
                "completion_reason": {
                  "type": "string"
                }
              },
              "required": [
                "task_id",
                "unit_id",
                "pass_id",
                "lens",
                "file_paths",
                "rationale"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "verified",
          "needs_followup"
        ],
        "additionalProperties": false
      },
      "run_id": {
        "type": "string"
      },
      "submitted_at": {
        "type": "string",
        "format": "date-time"
      },
      "instance_id": {
        "type": "string"
      },
      "identity_key": {
        "type": "string"
      },
      "idempotency_key": {
        "type": "string"
      },
      "emit_source": {
        "type": "string",
        "enum": [
          "base",
          "deepening",
          "steward",
          "redispatch"
        ]
      },
      "attempt": {
        "type": "integer",
        "minimum": 1
      }
    },
    "required": [
      "task_id",
      "unit_id",
      "pass_id",
      "lens",
      "file_coverage",
      "findings"
    ],
    "additionalProperties": false
  },
  "minItems": 1
}
