{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/planning-output.schema.json",
  "version": "1.1.0",
  "title": "Multi-Agent Pipeline  -  Phase 1 planning output",
  "description": "Contract for the Phase 1 task decomposition. Consumed by the Phase 2 TDD cycles  -  each task becomes one red→green→refactor iteration. 1.1.0 adds the plan-level reviewFocus[] and globalConstraints[].",
  "type": "object",
  "additionalProperties": false,
  "required": ["tasks", "approved"],
  "properties": {
    "approach": {
      "type": "string",
      "description": "One paragraph explaining the overall strategy  -  why this decomposition, what's deferred, what's in scope."
    },
    "tasks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "type", "files"],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^T[0-9]+$",
            "description": "Local task id, e.g. T1, T2."
          },
          "title": { "type": "string", "minLength": 4 },
          "type": {
            "type": "string",
            "enum": ["test", "code", "refactor", "docs", "chore"],
            "description": "test=new/updated test, code=production change, refactor=no-behavior-change cleanup, docs=documentation, chore=infra/config."
          },
          "files": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Files expected to change in this task. Phase 3 uses this to scope edits."
          },
          "dependsOn": {
            "type": "array",
            "items": { "type": "string", "pattern": "^T[0-9]+$" },
            "description": "Other task ids that must complete first. Phase 3 orchestrator respects ordering."
          },
          "acceptanceCriteria": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Bullet list of testable conditions that prove the task is done."
          },
          "requirements": {
            "type": "array",
            "items": { "type": "string" },
            "description": "Analysis requirement ids this task implements or tests (BR-<slug>-NN, FG-NN). spec-consistency-gate.mjs reads them, with any id in the title or acceptance criteria, to check that every requirement has a task and a test and that every task traces to a requirement."
          },
          "creates": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 },
            "description": "Files this task brings into existence. validate-planning.mjs fails a plan in which two tasks create the same file, and warns when a task that edits a created file is not ordered after its creator."
          },
          "removes": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 },
            "description": "Files or symbols this task deletes, or renames away (the old name). A name with a '/' or a file extension is a file. validate-planning.mjs warns when another task edits, consumes or creates what this task removes."
          },
          "produces": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 },
            "description": "Interfaces or symbols this task introduces or changes the shape of. validate-planning.mjs warns when a task that consumes one is not ordered after its producer."
          },
          "consumes": {
            "type": "array",
            "items": { "type": "string", "minLength": 1 },
            "description": "Interfaces or symbols this task calls or relies on without changing them. Paired against other tasks' produces and removes."
          },
          "design": {
            "type": "object",
            "additionalProperties": false,
            "required": ["component", "mapping"],
            "description": "The design source of a UI task. validate-planning.mjs --spec checks the component against the analysis Section 6 (Component Inventory) rows.",
            "properties": {
              "component": {
                "type": "string",
                "minLength": 1,
                "description": "The component name exactly as its Section 6 row names it."
              },
              "mapping": {
                "type": "string",
                "enum": ["code-connect", "new", "best-fit"],
                "description": "code-connect = the Code Connect mapped component, used verbatim; new = a Section 6 row marked not existing; best-fit = no mapping, pending design review (needs a Risk row; Phase 3 gates it review_blocking)."
              }
            }
          },
          "complexity": {
            "type": "object",
            "additionalProperties": false,
            "required": ["score"],
            "description": "Grounded size of the task, written by plan-complexity.mjs --write. A task with recommendSplit is split in Phase 1 before approval.",
            "properties": {
              "score": { "type": "integer", "minimum": 1, "maximum": 10 },
              "recommendSplit": {
                "type": "boolean",
                "description": "score is above prefs.global.planComplexity.splitAbove."
              },
              "factors": {
                "type": "object",
                "additionalProperties": false,
                "description": "The counts the score was built from. fanIn, crossModuleEdges and notIndexed are null when no code graph was available.",
                "properties": {
                  "files": { "type": "integer", "minimum": 0 },
                  "fanIn": { "type": ["integer", "null"], "minimum": 0 },
                  "modules": { "type": "integer", "minimum": 0 },
                  "crossModuleEdges": { "type": ["integer", "null"], "minimum": 0 },
                  "testSurface": { "type": "integer", "minimum": 0 },
                  "notIndexed": { "type": ["integer", "null"], "minimum": 0 }
                }
              }
            }
          }
        }
      }
    },
    "reviewFocus": {
      "type": "array",
      "maxItems": 5,
      "description": "Inputs or failure modes the spec implies but no task's tests exercise, each given to the task that owns the code so a test covers it. validate-planning.mjs fails an owner id that is not a task.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["input", "ownerTaskId"],
        "properties": {
          "input": {
            "type": "string",
            "minLength": 4,
            "description": "The input or failure mode, concretely (an empty list, a token that expired mid-request)."
          },
          "ownerTaskId": { "type": "string", "pattern": "^T[0-9]+$" }
        }
      }
    },
    "globalConstraints": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 },
      "description": "Project-wide values every task must respect, copied verbatim (a minimum OS version, a naming rule, a module boundary), because each task's implementer sees only its own task."
    },
    "approved": {
      "type": "boolean",
      "description": "User approved the plan (true) or changes requested (false → loop with feedback)."
    },
    "userFeedback": {
      "type": ["string", "null"],
      "description": "If approved=false, the user's requested changes. Re-run Phase 2 with this feedback."
    }
  }
}
