{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://github.com/Kucell/cortex-agent/schemas/task.schema.json",
  "title": "Cortex Agent Task",
  "description": "Mode-agnostic task entry in the Task Pipeline. A task advances through stage gates (draft / spec / plan / implement / validate / review / done) with required artifacts and evidence at each gate. Aligned with templates/_shared/.agent/tasks/task.schema.json minimal subset.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "task_id",
    "title",
    "description",
    "status",
    "stage",
    "priority",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "task_id": {
      "type": "string",
      "minLength": 1,
      "description": "Stable task id, e.g. T-FAE-001, M-001-MS-001."
    },
    "title": { "type": "string", "minLength": 1 },
    "description": { "type": "string", "minLength": 1 },
    "status": {
      "type": "string",
      "enum": ["draft", "active", "blocked", "completed", "canceled"]
    },
    "stage": {
      "type": "string",
      "enum": ["draft", "spec", "plan", "implement", "validate", "review", "done"]
    },
    "priority": { "type": "string", "enum": ["P0", "P1", "P2", "P3"] },
    "owner": { "type": ["string", "null"] },
    "mission_id": { "type": ["string", "null"] },
    "acceptance_criteria": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 }
    },
    "dependencies": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    },
    "subtasks": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    },
    "validation_commands": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 }
    },
    "gates": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["from_stage", "to_stage", "status"],
        "properties": {
          "from_stage": {
            "type": "string",
            "enum": ["draft", "spec", "plan", "implement", "validate", "review", "done"]
          },
          "to_stage": {
            "type": "string",
            "enum": ["draft", "spec", "plan", "implement", "validate", "review", "done"]
          },
          "status": {
            "type": "string",
            "enum": ["pending", "passed", "blocked", "waived"]
          },
          "required_artifacts": {
            "type": "array",
            "items": { "type": "string" }
          },
          "evidence_refs": {
            "type": "array",
            "items": { "type": "string" }
          },
          "checked_by": { "type": ["string", "null"] },
          "checked_at": { "type": ["string", "null"], "format": "date-time" },
          "reason": { "type": ["string", "null"] }
        },
        "additionalProperties": false
      }
    },
    "artifacts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["kind", "ref", "status"],
        "properties": {
          "kind": {
            "type": "string",
            "enum": ["spec", "architecture", "plan", "implementation", "validation", "review", "decision", "learning", "handoff", "release-note", "published-doc"]
          },
          "ref": { "type": "string", "minLength": 1 },
          "status": { "type": "string", "enum": ["draft", "final", "superseded"] }
        },
        "additionalProperties": false
      }
    },
    "created_at": { "type": "string", "format": "date-time" },
    "updated_at": { "type": "string", "format": "date-time" }
  }
}
