{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/pipeline/dev-critic-output.schema.json",
  "title": "Dev Critic Output",
  "description": "Schema for Phase 3.5 evaluator-optimizer (dev-critic) sub-agent output. Source: pipeline/agents/dev-critic.md. Pattern reference: Anthropic 'Building Effective Agents' (Dec 2024)  -  evaluator-optimizer.",
  "type": "object",
  "additionalProperties": false,
  "required": ["pass", "iteration", "gates", "findings"],
  "properties": {
    "pass": {
      "type": "boolean",
      "description": "true if all mandatory gates passed AND no blocking findings remain. false otherwise  -  generator must iterate."
    },
    "iteration": {
      "type": "integer",
      "minimum": 1,
      "maximum": 3,
      "description": "1-indexed critic round. 1 = full pass. 2 = re-check round-1 failures only. 3 = NOT recommended (escalate should be true)."
    },
    "escalate": {
      "type": "boolean",
      "default": false,
      "description": "true when critic has hit the loop cap (devCritic.maxIterations) and gates still fail. Orchestrator decides next step (pause user / proceed with logged failure / abort)."
    },
    "gates": {
      "type": "object",
      "additionalProperties": false,
      "required": ["build", "lint", "test", "secrets"],
      "properties": {
        "build": {
          "type": "object",
          "additionalProperties": false,
          "required": ["status"],
          "properties": {
            "status": { "type": "string", "enum": ["pass", "fail", "skipped"] },
            "skip_reason": {
              "type": "string",
              "description": "Required when status == 'skipped'. E.g. 'xcodebuild not installed on this runner'."
            },
            "error_summary": {
              "type": "string",
              "description": "First failure line + count when status == 'fail'."
            }
          }
        },
        "lint": {
          "type": "object",
          "additionalProperties": false,
          "required": ["status"],
          "properties": {
            "status": { "type": "string", "enum": ["pass", "fail", "skipped"] },
            "tool": { "type": "string", "description": "swiftlint | ktlint | eslint | ruff | ..." },
            "errors": { "type": "integer", "minimum": 0 },
            "warnings": { "type": "integer", "minimum": 0 },
            "skip_reason": { "type": "string" }
          }
        },
        "test": {
          "type": "object",
          "additionalProperties": false,
          "required": ["status"],
          "properties": {
            "status": { "type": "string", "enum": ["pass", "fail", "skipped"] },
            "passed": { "type": "integer", "minimum": 0 },
            "failed": { "type": "integer", "minimum": 0 },
            "skipped_count": { "type": "integer", "minimum": 0 },
            "skip_reason": { "type": "string" }
          }
        },
        "secrets": {
          "type": "object",
          "additionalProperties": false,
          "required": ["status"],
          "properties": {
            "status": { "type": "string", "enum": ["pass", "fail"] },
            "matched_patterns": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Pattern names that matched (never the actual secret value)."
            }
          }
        }
      }
    },
    "findings": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["severity", "file", "issue"],
        "properties": {
          "severity": { "type": "string", "enum": ["blocking", "important", "suggestion"] },
          "file": {
            "type": "string",
            "description": "Repo-relative path. For multi-repo tasks, prefixed with '<repo-name>/'."
          },
          "line": { "type": "integer", "minimum": 1 },
          "rule": {
            "type": "string",
            "description": "Citation. Format: 'rules/<file>.md#<anchor>' or 'gate/<name>'."
          },
          "issue": { "type": "string", "description": "Short, one-sentence description." },
          "fix": {
            "type": "string",
            "description": "Concrete suggestion the generator can act on without re-reading the rule."
          }
        }
      }
    },
    "duration_ms": { "type": "integer", "minimum": 0 },
    "tokens_in": { "type": "integer", "minimum": 0 },
    "tokens_out": { "type": "integer", "minimum": 0 },
    "stack": {
      "type": "string",
      "description": "Stack used for checklist selection (echoed from Phase 1 detectedStack).",
      "enum": ["ios", "android", "backend", "node", "python", "docker", "generic"]
    }
  }
}
