{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "$id": "https://cleo-dev.com/schemas/v1/research-manifest.schema.json",
  "title": "Agent Output Manifest Entry",
  "description": "DEPRECATED (ADR-027): Schema for legacy flat-file manifest entries. New agent outputs go to pipeline_manifest (tasks.db) via `cleo manifest append`. Retained as archive for migration reference.",
  "type": "object",
  "required": [
    "id",
    "file",
    "title",
    "date",
    "status",
    "topics",
    "key_findings",
    "actionable"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique identifier slug with date suffix",
      "pattern": "^[a-z0-9-]+-[0-9]{4}-[0-9]{2}-[0-9]{2}$"
    },
    "file": {
      "type": "string",
      "description": "Output filename in agent-outputs directory (relative path)",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}_[a-z0-9-]+\\.md$"
    },
    "title": {
      "type": "string",
      "description": "Human-readable title for the agent output entry",
      "minLength": 5,
      "maxLength": 200
    },
    "date": {
      "type": "string",
      "description": "ISO 8601 date (YYYY-MM-DD)",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
    },
    "timestamp": {
      "type": "string",
      "description": "ISO 8601 datetime for precise ordering",
      "format": "date-time"
    },
    "status": {
      "type": "string",
      "description": "Progress status of the agent output",
      "enum": ["complete", "partial", "blocked", "archived"]
    },
    "topics": {
      "type": "array",
      "description": "Categorization tags",
      "items": {"type": "string"},
      "minItems": 1,
      "maxItems": 10
    },
    "key_findings": {
      "type": "array",
      "description": "Executive summary (3-7 single-sentence findings)",
      "items": {
        "type": "string",
        "maxLength": 200
      },
      "minItems": 3,
      "maxItems": 7
    },
    "actionable": {
      "type": "boolean",
      "description": "Whether this agent output requires follow-up action"
    },
    "needs_followup": {
      "type": "array",
      "description": "Task IDs or BLOCKED:reason entries for handoff",
      "items": {
        "type": "string",
        "pattern": "^(T[0-9]+|BLOCKED:.+)$"
      },
      "default": []
    },
    "linked_tasks": {
      "type": "array",
      "description": "CLEO task IDs this agent output relates to",
      "items": {
        "type": "string",
        "pattern": "^T[0-9]+$"
      }
    },
    "agent_type": {
      "type": "string",
      "description": "Type of agent that created this output entry",
      "enum": ["research", "implementation", "validation", "documentation", "analysis", "specification"],
      "default": "research"
    },
    "source": {
      "type": "string",
      "description": "Origin of the entry (e.g., epic-architect)"
    },
    "output_file": {
      "type": "string",
      "description": "Relative path to output file in agent-outputs directory (alternative to file field)"
    },
    "files_modified": {
      "type": "array",
      "description": "Files modified by implementation agents (relative paths from project root)",
      "items": {
        "type": "string"
      }
    },
    "tests_run": {
      "type": "array",
      "description": "Test results from validation agents",
      "items": {
        "type": "object",
        "properties": {
          "test": {
            "type": "string",
            "description": "Test name or file path"
          },
          "result": {
            "type": "string",
            "enum": ["pass", "fail", "skip", "error"]
          },
          "details": {
            "type": "string",
            "description": "Optional failure details or notes"
          }
        },
        "required": ["test", "result"]
      }
    },
    "documentation_artifacts": {
      "type": "array",
      "description": "Documentation files created or updated by documentation agents",
      "items": {
        "type": "string"
      }
    },
    "parentId": {
      "type": ["string", "null"],
      "description": "Parent manifest entry ID for hierarchy (null for root entries)",
      "default": null
    },
    "epicId": {
      "type": ["string", "null"],
      "description": "Root epic task ID this entry belongs to",
      "pattern": "^T\\d+$",
      "default": null
    },
    "path": {
      "type": "string",
      "description": "Slash-delimited ancestry path from root epic (e.g., 'T2968/T2973/T2997')",
      "default": ""
    },
    "depth": {
      "type": "integer",
      "description": "Nesting depth (0=root, 1=child, 2=grandchild)",
      "minimum": 0,
      "maximum": 10,
      "default": 0
    },
    "childCount": {
      "type": "integer",
      "description": "Number of direct child entries",
      "minimum": 0,
      "default": 0
    },
    "audit": {
      "type": "object",
      "description": "Provenance and lifecycle tracking (v2.10.0+ - optional for backward compatibility)",
      "properties": {
        "created_by": {
          "type": "string",
          "description": "Agent ID that created this output (format: {role}-agent-{taskId})",
          "pattern": "^[a-z]+-agent-T[0-9]+$"
        },
        "created_at": {
          "type": "string",
          "description": "ISO 8601 datetime when output was created",
          "format": "date-time"
        },
        "validated_by": {
          "type": ["string", "null"],
          "description": "Agent ID that validated this output (MUST differ from created_by)",
          "pattern": "^[a-z]+-agent-T[0-9]+$"
        },
        "validated_at": {
          "type": ["string", "null"],
          "description": "ISO 8601 datetime when output was validated",
          "format": "date-time"
        },
        "validation_status": {
          "type": "string",
          "description": "Validation workflow state",
          "enum": ["pending", "in_review", "approved", "rejected", "needs_revision"],
          "default": "pending"
        },
        "tested_by": {
          "type": ["string", "null"],
          "description": "Agent ID that tested this output (MUST differ from created_by and validated_by)",
          "pattern": "^[a-z]+-agent-T[0-9]+$"
        },
        "tested_at": {
          "type": ["string", "null"],
          "description": "ISO 8601 datetime when output was tested",
          "format": "date-time"
        },
        "lifecycle_state": {
          "type": "string",
          "description": "RCSD→IVTR pipeline stage",
          "enum": ["research", "consensus", "specification", "decomposition", "implementation", "validation", "testing", "release"]
        },
        "provenance_chain": {
          "type": "array",
          "description": "Full lineage from research to release (array of task/manifest IDs or objects)",
          "items": {
            "oneOf": [
              {
                "type": "string",
                "description": "Simple ID reference",
                "pattern": "^(T[0-9]+|[a-z0-9-]+)$"
              },
              {
                "type": "object",
                "description": "Detailed chain entry",
                "required": ["type", "id"],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": ["task", "research", "consensus", "specification", "decomposition", "implementation", "validation", "testing", "release"]
                  },
                  "id": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  }
                }
              }
            ]
          },
          "default": []
        },
        "validates_task": {
          "type": "string",
          "description": "Task ID this output validates (for consensus/validation agents)",
          "pattern": "^T[0-9]+$"
        },
        "validation_result": {
          "type": "string",
          "description": "Result of validation (approved/rejected/needs_revision)",
          "enum": ["approved", "rejected", "needs_revision"]
        }
      },
      "required": ["created_by", "created_at", "lifecycle_state"]
    }
  },
  "additionalProperties": true
}
