{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://synkra.dev/schemas/task-v3-schema.json",
  "title": "AIOX Task V3 Schema",
  "description": "Schema for AIOX task definitions with Auto-Claude execution capabilities",
  "type": "object",
  "required": ["task"],
  "properties": {
    "frontmatter": {
      "type": "object",
      "description": "YAML frontmatter metadata",
      "properties": {
        "templates": {
          "type": "array",
          "description": "Template files this task uses",
          "items": { "type": "string" }
        },
        "tools": {
          "type": "array",
          "description": "MCP tools this task requires",
          "items": { "type": "string" }
        },
        "checklists": {
          "type": "array",
          "description": "Checklists to validate against",
          "items": { "type": "string" }
        }
      }
    },

    "task": {
      "type": "object",
      "description": "Core task definition (AIOX Task Format)",
      "required": ["name", "responsavel"],
      "properties": {
        "name": {
          "type": "string",
          "description": "Task function name (e.g., 'executeChecklist()')"
        },
        "responsavel": {
          "type": "string",
          "description": "Agent responsible for this task"
        },
        "responsavel_type": {
          "type": "string",
          "enum": ["Agente", "User", "System"],
          "default": "Agente"
        },
        "atomic_layer": {
          "type": "string",
          "enum": ["Atom", "Molecule", "Organism", "Template", "Page"],
          "description": "Atomic design layer classification"
        }
      }
    },

    "inputs": {
      "type": "array",
      "description": "Task input parameters",
      "items": {
        "type": "object",
        "required": ["campo", "tipo"],
        "properties": {
          "campo": {
            "type": "string",
            "description": "Parameter name"
          },
          "tipo": {
            "type": "string",
            "description": "Parameter type (string, object, array, boolean, number)"
          },
          "origem": {
            "type": "string",
            "description": "Data source (User Input, Context, File, etc.)"
          },
          "obrigatorio": {
            "type": "boolean",
            "description": "Whether parameter is required",
            "default": false
          },
          "validacao": {
            "type": "string",
            "description": "Validation rules"
          },
          "default": {
            "description": "Default value if not provided"
          }
        }
      }
    },

    "outputs": {
      "type": "array",
      "description": "Task output definitions",
      "items": {
        "type": "object",
        "required": ["campo", "tipo"],
        "properties": {
          "campo": {
            "type": "string",
            "description": "Output field name"
          },
          "tipo": {
            "type": "string",
            "description": "Output type"
          },
          "destino": {
            "type": "string",
            "description": "Output destination (File, Memory, State, etc.)"
          },
          "persistido": {
            "type": "boolean",
            "description": "Whether output is persisted",
            "default": false
          }
        }
      }
    },

    "executionModes": {
      "type": "object",
      "description": "Available execution modes for this task",
      "properties": {
        "yolo": {
          "type": "object",
          "description": "YOLO mode - fast, autonomous",
          "properties": {
            "enabled": { "type": "boolean", "default": true },
            "prompts": { "type": "string", "default": "0-1" },
            "description": { "type": "string" }
          }
        },
        "interactive": {
          "type": "object",
          "description": "Interactive mode - balanced, educational",
          "properties": {
            "enabled": { "type": "boolean", "default": true },
            "prompts": { "type": "string", "default": "5-10" },
            "description": { "type": "string" }
          }
        },
        "preflight": {
          "type": "object",
          "description": "Pre-flight mode - comprehensive planning",
          "properties": {
            "enabled": { "type": "boolean", "default": true },
            "description": { "type": "string" }
          }
        },
        "default": {
          "type": "string",
          "enum": ["yolo", "interactive", "preflight"],
          "default": "interactive"
        }
      }
    },

    "preConditions": {
      "type": "array",
      "description": "Conditions that must be true before task execution",
      "items": {
        "type": "object",
        "properties": {
          "condition": { "type": "string" },
          "errorMessage": { "type": "string" }
        }
      }
    },

    "steps": {
      "type": "array",
      "description": "Ordered execution steps",
      "items": {
        "type": "object",
        "required": ["id", "description"],
        "properties": {
          "id": {
            "type": "string",
            "description": "Step identifier (e.g., '1', '1.1', '5.5')"
          },
          "description": {
            "type": "string",
            "description": "What this step does"
          },
          "actions": {
            "type": "array",
            "description": "Specific actions to perform",
            "items": { "type": "string" }
          },
          "validation": {
            "type": "string",
            "description": "How to validate step completion"
          },
          "onFailure": {
            "type": "string",
            "enum": ["halt", "retry", "skip", "escalate"],
            "default": "halt"
          }
        }
      }
    },

    "autoClaude": {
      "type": "object",
      "description": "V3: Auto-Claude execution configuration",
      "properties": {
        "version": {
          "type": "string",
          "const": "3.0"
        },
        "migratedAt": {
          "type": "string",
          "format": "date-time"
        },
        "deterministic": {
          "type": "boolean",
          "description": "Whether task output is deterministic (same input = same output)",
          "default": true
        },
        "elicit": {
          "type": "boolean",
          "description": "Whether task requires user interaction/elicitation",
          "default": false
        },
        "composable": {
          "type": "boolean",
          "description": "Whether task can be called by other tasks",
          "default": true
        },
        "pipelinePhase": {
          "type": "string",
          "description": "Which pipeline phase this task belongs to",
          "enum": [
            "spec-gather",
            "spec-assess",
            "spec-research",
            "spec-write",
            "spec-critique",
            "plan-create",
            "plan-context",
            "plan-execute",
            "plan-verify",
            "recovery-track",
            "recovery-rollback",
            "qa-review",
            "qa-fix",
            "memory-capture",
            "memory-extract",
            "worktree-manage",
            "general"
          ]
        },
        "complexity": {
          "type": "string",
          "description": "Task complexity classification",
          "enum": ["simple", "standard", "complex"],
          "default": "standard"
        },
        "verification": {
          "type": "object",
          "description": "How to verify task completion",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["command", "api", "browser", "e2e", "manual", "none"],
              "default": "none"
            },
            "command": {
              "type": "string",
              "description": "Verification command to run"
            },
            "expectedOutput": {
              "type": "string",
              "description": "Expected output pattern (regex)"
            },
            "timeout": {
              "type": "integer",
              "description": "Verification timeout in seconds",
              "default": 30
            }
          }
        },
        "selfCritique": {
          "type": "object",
          "description": "Self-critique requirements for this task",
          "properties": {
            "required": {
              "type": "boolean",
              "description": "Whether self-critique is mandatory",
              "default": false
            },
            "checklistRef": {
              "type": "string",
              "description": "Reference to self-critique checklist"
            },
            "phases": {
              "type": "array",
              "description": "At which steps self-critique runs",
              "items": { "type": "string" }
            }
          }
        },
        "recovery": {
          "type": "object",
          "description": "Recovery configuration for this task",
          "properties": {
            "trackAttempts": {
              "type": "boolean",
              "description": "Whether to track execution attempts",
              "default": false
            },
            "maxRetries": {
              "type": "integer",
              "description": "Maximum retry attempts",
              "default": 3
            },
            "rollbackOnFailure": {
              "type": "boolean",
              "description": "Auto-rollback on failure",
              "default": false
            }
          }
        },
        "contextRequirements": {
          "type": "object",
          "description": "Context files needed for execution",
          "properties": {
            "projectContext": {
              "type": "boolean",
              "description": "Needs project-context.yaml",
              "default": false
            },
            "filesContext": {
              "type": "boolean",
              "description": "Needs files-context.yaml",
              "default": false
            },
            "implementationPlan": {
              "type": "boolean",
              "description": "Needs implementation.yaml",
              "default": false
            },
            "spec": {
              "type": "boolean",
              "description": "Needs spec.md",
              "default": false
            }
          }
        }
      }
    }
  }
}
