{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.kxm.dev/init-operation.schema.json",
  "title": "KXM Runtime-local initialization operation v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "operationId",
    "kind",
    "phase",
    "projectRoot",
    "projectId",
    "projectName",
    "templateId",
    "sourceTemplateRevision",
    "targetTemplateRevision",
    "planSha256",
    "files"
  ],
  "properties": {
    "schema": { "const": "kxm.init-operation.v1" },
    "operationId": { "type": "string", "pattern": "^op_[a-f0-9]{32}$" },
    "kind": { "enum": ["create", "repair"] },
    "phase": { "enum": ["preparing", "prepared", "applying", "verified"] },
    "projectRoot": { "type": "string", "minLength": 1, "maxLength": 32768, "pattern": "^(?:[A-Za-z]:[\\\\/]|\\\\\\\\|/)" },
    "projectId": { "$ref": "common.schema.json#/$defs/opaqueId" },
    "projectName": { "type": "string", "minLength": 1, "maxLength": 120, "pattern": "^[^\\u0000\\r\\n]+$" },
    "templateId": { "const": "builtin-minimal" },
    "sourceTemplateRevision": {
      "oneOf": [
        { "type": "null" },
        { "$ref": "common.schema.json#/$defs/sha256" }
      ]
    },
    "targetTemplateRevision": { "$ref": "common.schema.json#/$defs/sha256" },
    "planSha256": { "$ref": "common.schema.json#/$defs/sha256" },
    "files": {
      "type": "array",
      "minItems": 1,
      "maxItems": 128,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "observedSha256", "targetSha256", "classification", "action"],
        "properties": {
          "path": { "$ref": "common.schema.json#/$defs/relativePath" },
          "observedSha256": {
            "oneOf": [
              { "type": "null" },
              { "$ref": "common.schema.json#/$defs/sha256" }
            ]
          },
          "targetSha256": { "$ref": "common.schema.json#/$defs/sha256" },
          "classification": { "enum": ["template-only", "converged"] },
          "action": { "enum": ["create", "replace", "none"] }
        }
      }
    }
  }
}
