{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/analysis-output.schema.json",
  "version": "1.0.0",
  "title": "Multi-Agent Pipeline  -  Phase 1 analysis output",
  "description": "Contract for the Explorer subagent's summary in Phase 1. Drives Phase 2 task decomposition and Phase 4 review focus. Explorer must not mutate the codebase; output is read-only research.",
  "type": "object",
  "additionalProperties": false,
  "required": ["stack", "touchedAreas", "risks", "summary"],
  "properties": {
    "stack": {
      "type": "object",
      "additionalProperties": false,
      "required": ["primary"],
      "properties": {
        "primary": {
          "type": "string",
          "enum": ["ios", "android", "backend", "frontend", "mobile", "unknown"],
          "description": "Dominant stack inferred from project markers (.xcodeproj, build.gradle, package.json, etc.)."
        },
        "language": {
          "type": "string",
          "description": "E.g. 'Swift 6', 'Kotlin 2.1', 'Python 3.13', 'TypeScript 5'."
        },
        "framework": {
          "type": "string",
          "description": "E.g. 'SwiftUI', 'Jetpack Compose', 'FastAPI', 'Next.js 16'."
        }
      }
    },
    "touchedAreas": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "why"],
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1,
            "description": "File or directory relative to repo root."
          },
          "why": {
            "type": "string",
            "minLength": 4,
            "description": "Why the task likely affects this area."
          }
        }
      },
      "description": "Files / modules the task is most likely to modify. Phase 2 uses this to scope tasks."
    },
    "risks": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["risk", "severity"],
        "properties": {
          "risk": { "type": "string", "minLength": 4 },
          "severity": { "type": "string", "enum": ["low", "medium", "high"] },
          "mitigation": { "type": ["string", "null"] }
        }
      },
      "description": "Known hazards surfaced by exploration  -  concurrency hotspots, deprecated APIs, tech debt, missing tests."
    },
    "summary": {
      "type": "string",
      "minLength": 20,
      "description": "≤200 word plain-language summary for Phase 2 planning + user approval."
    },
    "docStatus": {
      "type": "string",
      "enum": ["produced", "reused", "not-applicable"],
      "description": "v15.17+ - what Phase 1 Step 4 did about the analysis document. `produced` wrote it, `reused` matched an existing evidence_digest (Locked 27), `not-applicable` means the task needs none (bugfix/chore with no Figma reference). Phase 2 and Phase 3 pre-flights branch on this instead of guessing from the filesystem, and `not-applicable` is a legitimate skip rather than an abort."
    },
    "docPath": {
      "type": "array",
      "items": { "type": "string" },
      "description": "v15.17+ - paths of the produced or reused per-platform documents, one per platform. Empty when docStatus is not-applicable.",
      "default": []
    },
    "openQuestions": {
      "type": "array",
      "items": { "type": "object" },
      "description": "v15.17+ - Section 20 rows still open after the post-analysis confirmation pass. Phase 4 flags any remaining row as review_blocking.",
      "default": []
    },
    "priorArt": {
      "type": "array",
      "description": "Advisory only. Up to 3 similar past-task triage matches injected AFTER the explorer returns (priorArtEnrichment). Not produced by the explorer and never required; present so the enriched object still validates under additionalProperties:false.",
      "items": { "type": "object" }
    }
  }
}
