{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "openmontage/pipelines/pipeline_manifest",
  "title": "Pipeline Manifest",
  "description": "Declarative pipeline definition specifying stages, artifacts, tools, and policies.",
  "type": "object",
  "required": ["name", "version", "stages"],
  "properties": {
    "name": { "type": "string" },
    "version": { "type": "string" },
    "description": { "type": "string" },
    "category": {
      "type": "string",
      "enum": ["talking_head", "generated", "hybrid", "screen_recording", "animation", "cinematic", "custom"]
    },
    "stability": {
      "type": "string",
      "enum": ["production", "beta"],
      "description": "Whether this pipeline has been audited and is considered stable"
    },
    "compatible_playbooks": {
      "oneOf": [
        {
          "type": "array",
          "items": { "type": "string" }
        },
        {
          "type": "object",
          "properties": {
            "recommended": { "type": "array", "items": { "type": "string" } },
            "also_works": { "type": "array", "items": { "type": "string" } },
            "custom_allowed": { "type": "boolean", "default": false }
          }
        }
      ]
    },
    "required_skills": {
      "type": "array",
      "items": { "type": "string" }
    },
    "stages": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": { "type": "string" },
          "agent": { "type": "string", "description": "Legacy: class name for Python-driven stages" },
          "skill": { "type": "string", "description": "Skill path for instruction-driven stages (e.g., pipelines/explainer/idea-director)" },
          "required_artifacts_in": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Artifact names that must exist before this stage runs"
          },
          "optional_artifacts_in": {
            "type": "array",
            "items": { "type": "string" }
          },
          "produces": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Artifact names this stage produces"
          },
          "preferred_tools": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Legacy: preferred tools for Python handlers"
          },
          "fallback_tools": {
            "type": "array",
            "items": { "type": "string" }
          },
          "required_tools": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Tools that must be available (or their fallback) for this stage to succeed"
          },
          "optional_tools": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Tools that enhance this stage but are not required"
          },
          "tools_available": {
            "type": "array",
            "items": { "type": "string" },
            "description": "All tools the agent can use in this stage (union of required + optional)"
          },
          "review_focus": {
            "type": "array",
            "items": { "type": "string" },
            "description": "What the reviewer checks after this stage"
          },
          "checkpoint_required": { "type": "boolean", "default": true },
          "human_approval_default": { "type": "boolean", "default": false },
          "success_criteria": {
            "type": "array",
            "items": { "type": "string" }
          },
          "sub_stages": {
            "type": "array",
            "description": "Optional sub-stages within a stage (e.g., sample preview for reference-driven productions)",
            "items": {
              "type": "object",
              "required": ["name"],
              "properties": {
                "name": { "type": "string" },
                "description": { "type": "string" },
                "condition": { "type": "string", "description": "When this sub-stage activates (e.g., video_analysis_brief_exists)" },
                "human_approval_default": { "type": "boolean", "default": true },
                "tools_available": { "type": "array", "items": { "type": "string" } },
                "review_focus": { "type": "array", "items": { "type": "string" } }
              }
            }
          }
        },
        "additionalProperties": false
      },
      "minItems": 1
    },
    "default_checkpoint_policy": {
      "type": "string",
      "enum": ["guided", "manual_all", "auto_noncreative"],
      "default": "guided"
    },
    "reference_input": {
      "type": "object",
      "description": "Configuration for reference video input support",
      "properties": {
        "supported": { "type": "boolean", "default": false },
        "analysis_depth": { "type": "string", "enum": ["transcript_only", "standard", "deep"], "default": "standard" },
        "analysis_tools": { "type": "array", "items": { "type": "string" } }
      }
    },
    "metadata": { "type": "object" },
    "orchestration": {
      "type": "object",
      "description": "Executive Producer orchestration config",
      "properties": {
        "mode": { "type": "string" },
        "skill": { "type": "string" },
        "budget_default_usd": { "type": "number" },
        "max_revisions_per_stage": { "type": "integer" },
        "max_send_backs": { "type": "integer" },
        "max_wall_time_minutes": { "type": "integer" }
      },
      "additionalProperties": false
    },
    "extensions": {
      "type": "object",
      "description": "Capability extension permissions for this pipeline",
      "properties": {
        "custom_scripts": { "type": "boolean", "default": true },
        "custom_playbooks": { "type": "boolean", "default": true },
        "custom_skills": { "type": "boolean", "default": true },
        "custom_tools": { "type": "boolean", "default": false }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
