{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Analyst Output",
  "type": "object",
  "required": [
    "task_id",
    "issue_summary",
    "affected_layers",
    "affected_files",
    "existing_patterns",
    "related_tests",
    "security_surface",
    "assumptions",
    "risks_discovered"
  ],
  "properties": {
    "task_id": { "type": "string", "minLength": 1 },
    "issue_summary": { "type": "string", "minLength": 1 },
    "affected_layers": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "enum": ["Repository", "Service", "pages", "templates", "web/js", "web/css", "modules", "config", "db", "bin"]
      }
    },
    "affected_files": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["path", "role"],
        "properties": {
          "path": { "type": "string", "minLength": 1 },
          "role": { "type": "string", "minLength": 1 }
        },
        "additionalProperties": false
      }
    },
    "existing_patterns": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Partials, helpers, services, or conventions already in use for this area."
    },
    "related_tests": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Existing test files relevant to the change."
    },
    "security_surface": {
      "type": "object",
      "properties": {
        "authz_relevant": { "type": "boolean" },
        "tenant_scope_relevant": { "type": "boolean" },
        "input_handling": { "type": "boolean" },
        "crypto_relevant": { "type": "boolean" },
        "file_upload_relevant": { "type": "boolean" },
        "notes": { "type": "string" }
      },
      "additionalProperties": false
    },
    "module_context": {
      "type": "object",
      "description": "Present only when a module is involved.",
      "properties": {
        "module_id": { "type": "string" },
        "active": { "type": "boolean" },
        "manifest_declarations": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "assumptions": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Ambiguities the Planner must resolve."
    },
    "risks_discovered": {
      "type": "array",
      "items": { "type": "string" }
    }
  },
  "additionalProperties": false
}
