{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.antfleet.dev/schemas/acp/review-deliverable-v0.json",
  "title": "AntFleet ACP review deliverable",
  "description": "Structured AntFleet review result for a public GitHub pull request, including target metadata, two-model agreement metadata, receipt state, and consensus findings.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_version", "status", "job", "target", "review", "receipt", "findings"],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "antfleet.acp.review.deliverable.v0",
      "description": "Deliverable schema version."
    },
    "status": {
      "type": "string",
      "description": "Terminal review result state.",
      "enum": ["complete", "complete_no_findings", "receipt_pending"]
    },
    "job": {
      "type": "object",
      "description": "ACP and AntFleet job identifiers plus the public status URL.",
      "additionalProperties": false,
      "required": ["acp_job_id", "antfleet_job_id", "provider_agent", "status_url"],
      "properties": {
        "acp_job_id": {
          "type": "string",
          "maxLength": 160,
          "description": "Virtuals ACP job identifier."
        },
        "antfleet_job_id": {
          "type": "string",
          "maxLength": 160,
          "description": "Internal AntFleet review job identifier."
        },
        "provider_agent": {
          "type": "string",
          "maxLength": 120,
          "description": "Provider agent name."
        },
        "client_agent_wallet": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$",
          "description": "Authenticated ACP client wallet when included."
        },
        "status_url": {
          "type": "string",
          "format": "uri",
          "description": "Public AntFleet job status URL."
        }
      }
    },
    "target": {
      "type": "object",
      "description": "Pinned public GitHub pull request target that was reviewed.",
      "additionalProperties": false,
      "required": ["repo", "mode", "head_sha"],
      "properties": {
        "repo": {
          "type": "string",
          "maxLength": 260,
          "description": "GitHub repository in owner/name form."
        },
        "mode": {
          "type": "string",
          "const": "pr",
          "description": "Review mode; v0 reviews pull requests."
        },
        "pr": { "type": "integer", "minimum": 1, "description": "Pull request number." },
        "head_sha": {
          "type": "string",
          "pattern": "^[0-9a-fA-F]{7,64}$",
          "description": "Pinned pull request head SHA reviewed by AntFleet."
        },
        "files_reviewed": {
          "type": "array",
          "description": "Changed files included in the review.",
          "items": { "type": "string", "maxLength": 512 }
        }
      }
    },
    "review": {
      "type": "object",
      "description": "Two-model review metadata and execution details.",
      "additionalProperties": false,
      "required": ["review_id", "agreement_mode", "reviewer_count", "degraded", "model_ids"],
      "properties": {
        "review_id": {
          "type": "string",
          "maxLength": 160,
          "description": "AntFleet review identifier."
        },
        "agreement_mode": {
          "type": "string",
          "const": "unanimous",
          "description": "Consensus mode used for posted findings."
        },
        "reviewer_count": {
          "type": "integer",
          "const": 2,
          "description": "Number of independent reviewers."
        },
        "degraded": {
          "type": "boolean",
          "const": false,
          "description": "Success deliverables are never degraded."
        },
        "degraded_reason": {
          "type": "null",
          "description": "Always null for success deliverables."
        },
        "model_ids": {
          "type": "object",
          "description": "Model identifiers used by each reviewer.",
          "additionalProperties": { "type": "string", "maxLength": 160 }
        },
        "duration_ms": {
          "type": "integer",
          "minimum": 0,
          "description": "Review runtime in milliseconds."
        }
      }
    },
    "receipt": {
      "type": "object",
      "description": "Review receipt URL and finding receipt state.",
      "additionalProperties": false,
      "required": ["state", "review_receipt_url", "finding_receipt_urls"],
      "properties": {
        "state": {
          "type": "string",
          "description": "Receipt publication state.",
          "enum": ["review_receipt_ready", "finding_receipts_pending", "no_findings", "unavailable"]
        },
        "review_receipt_url": {
          "type": ["string", "null"],
          "format": "uri",
          "description": "Public review receipt URL when available."
        },
        "finding_receipt_urls": {
          "type": "array",
          "description": "Closure receipt URLs for findings when available.",
          "items": { "type": "string", "format": "uri" }
        },
        "receipt_note": {
          "type": "string",
          "maxLength": 500,
          "description": "Human-readable receipt state note."
        }
      }
    },
    "findings": {
      "type": "array",
      "description": "Consensus findings agreed by both reviewers.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "finding_id",
          "title",
          "severity",
          "category",
          "confidence",
          "evidence",
          "reasoning",
          "reproduction",
          "recommendation",
          "whyTestsDoNotAlreadyCoverThis",
          "suggestedRegressionTest",
          "minimumFixScope",
          "requiresPolicyReview",
          "upstreamOrigin",
          "status"
        ],
        "properties": {
          "finding_id": { "type": "string", "maxLength": 160 },
          "title": { "type": "string", "maxLength": 240 },
          "severity": { "type": "string", "enum": ["critical", "high", "medium", "low"] },
          "category": {
            "type": "string",
            "enum": [
              "bug",
              "security",
              "performance",
              "concurrency",
              "api-contract",
              "data-loss",
              "test-gap",
              "docs-gap",
              "build-release",
              "maintainability"
            ]
          },
          "confidence": { "type": "string", "enum": ["high", "medium", "low"] },
          "evidence": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": ["path", "startLine", "endLine", "symbol", "quote"],
              "properties": {
                "path": { "type": "string", "maxLength": 512 },
                "startLine": { "type": ["integer", "null"], "minimum": 1 },
                "endLine": { "type": ["integer", "null"], "minimum": 1 },
                "symbol": { "type": ["string", "null"], "maxLength": 160 },
                "quote": { "type": ["string", "null"], "maxLength": 600 }
              }
            }
          },
          "reasoning": { "type": "string", "maxLength": 4000 },
          "reproduction": { "type": ["string", "null"], "maxLength": 4000 },
          "recommendation": { "type": "string", "maxLength": 4000 },
          "whyTestsDoNotAlreadyCoverThis": { "type": "string", "maxLength": 2000 },
          "suggestedRegressionTest": { "type": ["string", "null"], "maxLength": 2000 },
          "minimumFixScope": { "type": "string", "maxLength": 2000 },
          "requiresPolicyReview": { "type": "boolean" },
          "upstreamOrigin": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": ["package", "reason"],
                "properties": {
                  "package": { "type": "string", "maxLength": 200 },
                  "reason": { "type": "string", "maxLength": 1000 }
                }
              },
              { "type": "null" }
            ]
          },
          "status": {
            "type": "string",
            "enum": ["open", "closed", "superseded", "not_posted"]
          },
          "receipt_url": { "type": ["string", "null"], "format": "uri" }
        }
      }
    },
    "disclaimer": {
      "type": "string",
      "maxLength": 500,
      "description": "Required when reviewing trading-agent or financial workflow code."
    }
  }
}
