{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://loopxxi.com/downloads/loop-scope-auditor.schema.json",
  "title": "Loop Scope Agent Specification Auditor 0.1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "tool",
    "method",
    "model",
    "requester",
    "missing_requirements",
    "ambiguities",
    "conflicts",
    "risks",
    "suggested_acceptance_tests",
    "questions_for_requester",
    "confidence",
    "billing"
  ],
  "properties": {
    "schema_version": { "const": "0.1" },
    "tool": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "const": "loop-scope-auditor" },
        "version": { "type": "string" }
      }
    },
    "method": { "const": "heuristic" },
    "model": { "type": ["string", "null"] },
    "requester": {
      "type": "object",
      "additionalProperties": false,
      "required": ["agent_id"],
      "properties": {
        "agent_id": { "type": ["string", "null"] }
      }
    },
    "missing_requirements": {
      "type": "array",
      "items": { "$ref": "#/$defs/finding" }
    },
    "ambiguities": {
      "type": "array",
      "items": { "$ref": "#/$defs/finding" }
    },
    "conflicts": {
      "type": "array",
      "items": { "$ref": "#/$defs/finding" }
    },
    "risks": {
      "type": "array",
      "items": { "$ref": "#/$defs/finding" }
    },
    "suggested_acceptance_tests": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "format", "status", "given", "when", "then", "check"],
        "properties": {
          "id": { "type": "string" },
          "title": { "type": "string" },
          "format": { "const": "gherkin" },
          "status": { "enum": ["runnable_if_implemented", "blocked_by_gap"] },
          "given": { "type": "string" },
          "when": { "type": "string" },
          "then": { "type": "string" },
          "check": { "type": "object" }
        }
      }
    },
    "questions_for_requester": {
      "type": "array",
      "items": { "type": "string" }
    },
    "confidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["score", "label", "rationale"],
      "properties": {
        "score": { "type": "number", "minimum": 0, "maximum": 1 },
        "label": { "enum": ["low", "medium", "high"] },
        "rationale": { "type": "string" }
      }
    },
    "billing": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "note"],
      "properties": {
        "status": { "const": "not_open" },
        "note": { "type": "string" }
      }
    }
  },
  "$defs": {
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "area", "severity", "detail", "evidence"],
      "properties": {
        "id": { "type": "string" },
        "area": { "type": "string" },
        "severity": { "enum": ["high", "medium", "low"] },
        "phrase": { "type": "string" },
        "detail": { "type": "string" },
        "evidence": { "type": ["string", "null"] }
      }
    }
  }
}
