{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/bigKING67/pi-67/schemas/pi67-update-plan.schema.json",
  "title": "pi-67 update plan",
  "type": "object",
  "required": ["schema", "createdAt", "manager", "paths", "actions", "blocked", "warnings", "recommendations"],
  "properties": {
    "schema": {
      "const": "pi67.update-plan.v1"
    },
    "createdAt": {
      "type": "string"
    },
    "operationSnapshot": {
      "type": "object",
      "required": ["schema", "capturedAt", "manager", "current", "target", "live"],
      "properties": {
        "schema": { "const": "pi67.operation-snapshot.v1" },
        "capturedAt": { "type": "string" },
        "manager": {
          "type": "object",
          "required": ["package", "version", "root"],
          "properties": {
            "package": { "type": "string" },
            "version": { "type": "string" },
            "root": { "type": "string" }
          },
          "additionalProperties": true
        },
        "current": {
          "type": "object",
          "required": ["kind", "activated", "version", "releasePath"],
          "properties": {
            "kind": { "type": "string" },
            "activated": { "type": "boolean" },
            "version": { "type": "string" },
            "releasePath": { "type": "string" }
          },
          "additionalProperties": true
        },
        "target": {
          "type": "object",
          "required": ["version", "sourceRoot"],
          "properties": {
            "version": { "type": "string" },
            "sourceRoot": { "type": "string" }
          },
          "additionalProperties": true
        },
        "live": {
          "type": "object",
          "required": ["agentDir", "stateDir", "exists", "defaultProvider", "defaultModel", "theme"],
          "properties": {
            "agentDir": { "type": "string" },
            "stateDir": { "type": "string" },
            "exists": { "type": "boolean" },
            "defaultProvider": { "type": "string" },
            "defaultModel": { "type": "string" },
            "theme": { "type": "string" }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    },
    "manager": {
      "type": "object",
      "required": ["package", "version"],
      "properties": {
        "package": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "registry": {
          "type": "object",
          "description": "npm registry latest-version check; skipped when --no-remote is used."
        }
      },
      "additionalProperties": true
    },
    "paths": {
      "type": "object"
    },
    "policy": {
      "type": "object",
      "description": "Non-destructive update policy in force for user config, theme selection, shared skills, and external repos.",
      "required": ["preservedRuntimeFiles", "themePolicy", "sharedSkillsPolicy", "externalDirtyPolicy"],
      "properties": {
        "userConfigPolicy": {
          "type": "string"
        },
        "preservedRuntimeFiles": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "themePolicy": {
          "type": "string"
        },
        "sharedSkillsPolicy": {
          "type": "string"
        },
        "externalDirtyPolicy": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "extensions": {
      "type": "object",
      "required": ["schema", "policy", "summary", "extensions", "unknown"],
      "properties": {
        "schema": { "const": "pi67.managed-extensions-status.v1" },
        "policy": { "type": "object" },
        "summary": {
          "type": "object",
          "required": [
            "total",
            "missing",
            "belowBaseline",
            "atBaseline",
            "userManagedAhead",
            "userManagedDiverged",
            "loadFailed",
            "unknown",
            "automaticActions"
          ],
          "properties": {
            "total": { "type": "integer", "minimum": 0 },
            "missing": { "type": "integer", "minimum": 0 },
            "belowBaseline": { "type": "integer", "minimum": 0 },
            "atBaseline": { "type": "integer", "minimum": 0 },
            "userManagedAhead": { "type": "integer", "minimum": 0 },
            "userManagedDiverged": { "type": "integer", "minimum": 0 },
            "loadFailed": { "type": "integer", "minimum": 0 },
            "unknown": { "type": "integer", "minimum": 0 },
            "automaticActions": { "type": "integer", "minimum": 0 }
          },
          "additionalProperties": true
        },
        "extensions": { "type": "array", "minItems": 21 },
        "unknown": { "type": "array" }
      },
      "additionalProperties": true
    },
    "skillPacks": {
      "type": "object",
      "description": "Read-only version/parity status for registered shared Skill Packs.",
      "required": ["schemaId", "registry", "summary", "packs", "errors"],
      "properties": {
        "schemaId": {
          "const": "pi67-shared-skill-packs-status/v1"
        },
        "registry": {
          "type": "object",
          "required": ["path", "exists", "valid"],
          "properties": {
            "path": { "type": "string" },
            "exists": { "type": "boolean" },
            "valid": { "type": "boolean" }
          },
          "additionalProperties": true
        },
        "summary": {
          "type": "object",
          "required": ["packs", "consistent", "attention"],
          "properties": {
            "packs": { "type": "integer", "minimum": 0 },
            "consistent": { "type": "integer", "minimum": 0 },
            "attention": { "type": "integer", "minimum": 0 }
          },
          "additionalProperties": true
        },
        "packs": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name", "version", "skills", "identical", "missing", "conflicts", "consistent"],
            "properties": {
              "name": { "type": "string", "minLength": 1 },
              "version": { "type": "string", "minLength": 1 },
              "skills": { "type": "integer", "minimum": 1 },
              "identical": { "type": "integer", "minimum": 0 },
              "missing": { "type": "integer", "minimum": 0 },
              "conflicts": { "type": "integer", "minimum": 0 },
              "consistent": { "type": "boolean" }
            },
            "additionalProperties": true
          }
        },
        "errors": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": true
    },
    "actions": {
      "type": "array",
      "description": "Safe update/repair actions that preserve user-owned config and local choices.",
      "items": {
        "type": "object",
        "required": ["id", "kind", "operation", "writes", "preserves", "risk", "reason"],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "type": "string",
            "minLength": 1
          },
          "operation": {
            "type": "string",
            "minLength": 1
          },
          "writes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "preserves": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "risk": {
            "enum": ["low", "medium", "high"]
          },
          "reason": {
            "type": "string"
          },
          "explicitCommand": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "blocked": {
      "type": "array",
      "description": "Actions blocked to preserve user state, dirty repos, detached repos, or strict-mode policy.",
      "items": {
        "type": "object",
        "required": ["id", "kind", "reason"],
        "properties": {
          "id": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          },
          "recovery": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "recommendations": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "additionalProperties": true
}
