{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "dd-flow/plan-stage-report@5",
  "title": "Generated PLAN receipt projection",
  "description": "A deterministic lifecycle receipt. It references the canonical plan and aspect map but never copies their semantic items.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema_id", "generated_at", "protocol", "overall", "route", "plan_ref", "aspect_map_ref", "execution_summary", "delta_lint", "transition", "handoff"],
  "properties": {
    "schema_id": {"const": "dd-flow/plan-stage-report@5"},
    "generated_at": {"type": "string", "format": "date-time"},
    "protocol": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "title", "project", "branch", "stage"],
      "properties": {
        "id": {"type": "string", "minLength": 1},
        "title": {"type": "string", "minLength": 1},
        "project": {"type": "string", "minLength": 1},
        "branch": {"type": "string", "minLength": 1},
        "stage": {"const": "plan"}
      }
    },
    "overall": {
      "type": "object",
      "additionalProperties": false,
      "required": ["verdict", "verdict_label", "score", "score_max", "next_action", "summary"],
      "properties": {
        "verdict": {"enum": ["plan_ready", "ready_for_code", "needs_user_decision", "plan_blocked", "degraded"]},
        "verdict_label": {"type": "string", "minLength": 1},
        "score": {"type": "number", "minimum": 0},
        "score_max": {"type": "number", "exclusiveMinimum": 0},
        "next_action": {"type": "string", "minLength": 1},
        "summary": {"type": "string", "minLength": 1}
      }
    },
    "route": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["label", "value", "note"],
        "properties": {
          "label": {"type": "string", "minLength": 1},
          "value": {"type": "string", "minLength": 1},
          "note": {"type": "string", "minLength": 1}
        }
      }
    },
    "plan_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "plan_id", "revision", "sha256", "item_count"],
      "properties": {
        "path": {"type": "string", "pattern": "^\\.memory-bank/protocol/[^/]+/plan\\.json$"},
        "plan_id": {"type": "string", "minLength": 1},
        "revision": {"type": "integer", "minimum": 1},
        "sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
        "item_count": {"type": "integer", "minimum": 1}
      }
    },
    "aspect_map_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256", "coverage_count"],
      "properties": {
        "path": {"type": "string", "minLength": 1},
        "sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
        "coverage_count": {"type": "integer", "minimum": 0}
      }
    },
    "execution_summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["wall_clock_ms"],
      "properties": {
        "wall_clock_ms": {"type": "integer", "minimum": 0},
        "available_subagent_slots": {"type": "integer", "minimum": 0}
      }
    },
    "delta_lint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "selected_files", "finding_count"],
      "properties": {
        "status": {"enum": ["passed", "failed", "not_applicable_no_changed_docs", "unavailable"]},
        "selected_files": {"type": "array", "items": {"type": "string", "minLength": 1}},
        "finding_count": {"type": "integer", "minimum": 0}
      }
    },
    "transition": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "next_stage"],
      "properties": {
        "status": {"enum": ["applied", "blocked", "not_applicable"]},
        "next_stage": {"type": "string", "minLength": 1}
      }
    },
    "handoff": {
      "type": "object",
      "additionalProperties": false,
      "required": ["code_prompt", "must_read", "next_gate"],
      "properties": {
        "code_prompt": {"type": "string", "minLength": 1},
        "must_read": {"type": "array", "minItems": 1, "items": {"type": "string", "minLength": 1}},
        "next_gate": {"type": "string", "minLength": 1}
      }
    }
  }
}
