{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://fouria.io/schemas/sandbox-v1-evaluation-plan.schema.json",
  "title": "FourIA Sandbox v1 migration evaluation plan",
  "description": "Machine-readable plan that maps every implemented V1 capability (docs/releases/V1-RELEASE-NOTES.md) to a domain, a migration milestone and a v1 disposition, and defines the five-step protocol every milestone executes.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "plan_version",
    "generated_from",
    "branch",
    "staging",
    "domains",
    "protocol",
    "milestones",
    "features",
    "deprecations",
    "out_of_scope",
    "summary"
  ],
  "properties": {
    "$schema": { "type": "string" },
    "plan_version": { "const": 1 },
    "generated_from": {
      "type": "object",
      "additionalProperties": false,
      "required": ["release_notes", "release_notes_commit", "guideline"],
      "properties": {
        "release_notes": { "type": "string" },
        "release_notes_commit": { "type": "string" },
        "guideline": {
          "type": "object",
          "additionalProperties": false,
          "required": ["normative", "adr_log", "reference", "source_ref", "skills", "invariants"],
          "properties": {
            "normative": { "type": "string" },
            "adr_log": { "type": "string" },
            "reference": { "type": "string" },
            "source_ref": { "type": "string" },
            "skills": { "type": "array", "items": { "type": "string" } },
            "invariants": {
              "type": "object",
              "patternProperties": { "^C([1-9]|10)$": { "type": "string" } },
              "additionalProperties": false
            }
          }
        }
      }
    },
    "branch": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "base",
        "base_commit",
        "worktree",
        "independent_track",
        "strategy",
        "sync_command",
        "changeset"
      ],
      "properties": {
        "name": { "const": "v1-sandbox" },
        "base": { "type": "string" },
        "base_commit": { "type": "string" },
        "worktree": { "type": "string" },
        "independent_track": { "type": "boolean" },
        "strategy": { "type": "string" },
        "sync_command": { "type": "string" },
        "changeset": { "type": "string" }
      }
    },
    "staging": {
      "type": "object",
      "additionalProperties": false,
      "required": ["lerma_client", "hostnames", "reserved_client_slug", "authority", "note"],
      "properties": {
        "lerma_client": {
          "type": "object",
          "additionalProperties": false,
          "required": ["slug", "id", "instances"],
          "properties": {
            "slug": { "const": "client-sandbox-v1" },
            "id": { "const": 20 },
            "instances": { "const": 2 }
          }
        },
        "hostnames": {
          "type": "object",
          "additionalProperties": false,
          "required": ["dev", "production"],
          "properties": {
            "dev": { "type": "string" },
            "production": { "type": "string" }
          }
        },
        "reserved_client_slug": { "const": "client" },
        "authority": { "type": "string" },
        "note": { "type": "string" }
      }
    },
    "domains": {
      "type": "array",
      "minItems": 4,
      "maxItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "label", "purpose"],
        "properties": {
          "id": {
            "enum": ["openclaw-management", "persistence", "billing", "security"]
          },
          "label": { "type": "string" },
          "purpose": { "type": "string" }
        }
      }
    },
    "protocol": {
      "type": "object",
      "additionalProperties": false,
      "required": ["description", "steps", "definition_of_done"],
      "properties": {
        "description": { "type": "string" },
        "steps": {
          "type": "array",
          "minItems": 5,
          "maxItems": 5,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["step", "id", "action", "required_output"],
            "properties": {
              "step": { "type": "integer", "minimum": 1, "maximum": 5 },
              "id": {
                "enum": ["prerequisites", "e2e_suitability", "execute", "verify", "staging"]
              },
              "action": { "type": "string" },
              "required_output": { "type": "string" }
            }
          }
        },
        "definition_of_done": { "type": "array", "items": { "type": "string" } }
      }
    },
    "milestones": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/milestone" }
    },
    "features": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/feature" }
    },
    "deprecations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "item", "replaces_with", "phase", "reason"],
        "properties": {
          "id": { "type": "string", "pattern": "^DEP-[0-9]+$" },
          "item": { "type": "string" },
          "replaces_with": { "type": "string" },
          "phase": { "type": "string" },
          "reason": { "type": "string" }
        }
      }
    },
    "out_of_scope": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "title", "status", "reason"],
        "properties": {
          "id": { "type": "string", "pattern": "^[CO]-[0-9]+$" },
          "title": { "type": "string" },
          "status": { "enum": ["🧪", "❌"] },
          "reason": { "type": "string" }
        }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "implemented_features",
        "by_status",
        "by_domain",
        "by_disposition",
        "by_impact",
        "milestones",
        "out_of_scope_features"
      ],
      "properties": {
        "implemented_features": { "type": "integer", "minimum": 0 },
        "by_status": { "type": "object", "additionalProperties": { "type": "integer" } },
        "by_domain": { "type": "object", "additionalProperties": { "type": "integer" } },
        "by_disposition": { "type": "object", "additionalProperties": { "type": "integer" } },
        "by_impact": { "type": "object", "additionalProperties": { "type": "integer" } },
        "milestones": { "type": "integer", "minimum": 1 },
        "out_of_scope_features": { "type": "integer", "minimum": 0 }
      }
    }
  },
  "$defs": {
    "milestone": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "domain",
        "title",
        "slices",
        "invariants",
        "prerequisites",
        "e2e_suitability",
        "execute",
        "verify",
        "staging",
        "features"
      ],
      "properties": {
        "id": { "type": "string", "pattern": "^(M[0-9]+|(SEC|PER|BIL|OCM)-[0-9]+)$" },
        "domain": {
          "enum": ["openclaw-management", "persistence", "billing", "security", null]
        },
        "title": { "type": "string" },
        "slices": {
          "type": "array",
          "items": { "enum": ["S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7"] }
        },
        "invariants": {
          "type": "array",
          "items": { "enum": ["C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10"] }
        },
        "prerequisites": {
          "type": "object",
          "additionalProperties": false,
          "required": ["read", "find_replace", "expected_result"],
          "properties": {
            "read": { "type": "array", "items": { "type": "string" } },
            "find_replace": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["file", "find", "replace"],
                "properties": {
                  "file": { "type": "string" },
                  "find": { "type": "string" },
                  "replace": { "type": "string" }
                }
              }
            },
            "expected_result": { "type": "string" }
          }
        },
        "e2e_suitability": {
          "type": "object",
          "additionalProperties": false,
          "required": ["verdict", "existing", "gaps", "required"],
          "properties": {
            "verdict": { "enum": ["suitable", "partial", "unsuitable"] },
            "existing": { "type": "array", "items": { "type": "string" } },
            "gaps": { "type": "array", "items": { "type": "string" } },
            "required": { "type": "array", "items": { "type": "string" } }
          }
        },
        "execute": {
          "type": "object",
          "additionalProperties": false,
          "required": ["docs", "steps"],
          "properties": {
            "docs": { "type": "array", "items": { "type": "string" } },
            "steps": { "type": "array", "items": { "type": "string" } }
          }
        },
        "verify": {
          "type": "object",
          "additionalProperties": false,
          "required": ["commands", "acceptance"],
          "properties": {
            "commands": { "type": "array", "items": { "type": "string" } },
            "acceptance": { "type": "array", "items": { "type": "string" } }
          }
        },
        "staging": {
          "type": "object",
          "additionalProperties": false,
          "required": ["target", "deploy", "observe", "abort_criteria"],
          "properties": {
            "target": { "type": "string" },
            "deploy": { "type": "array", "items": { "type": "string" } },
            "observe": { "type": "array", "items": { "type": "string" } },
            "abort_criteria": { "type": "array", "items": { "type": "string" } }
          }
        },
        "features": {
          "type": "array",
          "items": { "type": "string", "pattern": "^[CO]-[0-9]+$" }
        }
      }
    },
    "feature": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "title",
        "status",
        "source_section",
        "domain",
        "milestone",
        "disposition",
        "impact",
        "reason",
        "release_notes"
      ],
      "properties": {
        "id": { "type": "string", "pattern": "^[CO]-[0-9]+$" },
        "title": { "type": "string" },
        "status": { "enum": ["✅", "🟡", "🧭"] },
        "source_section": { "type": "string" },
        "domain": { "enum": ["openclaw-management", "persistence", "billing", "security"] },
        "milestone": { "type": "string" },
        "disposition": { "enum": ["preserve", "verify", "rewrite", "deprecate"] },
        "impact": {
          "enum": [
            "control-plane",
            "edge-auth",
            "gateway-api",
            "container-exec",
            "container-lifecycle",
            "backup",
            "outbound",
            "queue",
            "billing",
            "observability",
            "docs",
            "partial"
          ]
        },
        "reason": { "type": "string" },
        "release_notes": { "type": "string" }
      }
    }
  }
}
