{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aslice.sh/schematics/json/operation-request.schema.json",
  "title": "Operation request",
  "description": "Version 1 structural contract. Normative field semantics: docs/STATE-AND-RECOVERY.md section 10.2 and docs/DATABASE.md section 9. Cryptography, canonical encoding, chain continuity, ordering, and filesystem safety require semantic validation. Version 2: explicit source-work consent, namespace selections, and security/restart decisions. Old versions are rejected; regenerate from authenticated inputs, never infer consent. Field semantics: docs/DESIGN.md vulnerability-and-sbom-pipeline and docs/PACKAGE-FORMAT.md Security dependency and selection records.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": 2
    },
    "action": {
      "enum": [
        "status",
        "stop",
        "continue",
        "manual",
        "salvage",
        "activate",
        "upgrade",
        "apply",
        "needs-restarting",
        "install"
      ]
    },
    "operation_id": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^[0-9a-f]{32}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "plan_digest": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "dry_run": {
      "type": "boolean"
    },
    "accept_system_changes": {
      "type": "boolean"
    },
    "accept_grafts": {
      "type": "boolean"
    },
    "allow_source_builds": {
      "type": "boolean"
    },
    "selections": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "kind": {
            "enum": [
              "provider",
              "alias",
              "replacement"
            ]
          },
          "requested": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]*:[a-z0-9][a-z0-9-]*$"
          },
          "selected": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]*:[a-z0-9][a-z0-9-]*$"
          },
          "repository_identity": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "kind",
          "requested",
          "selected",
          "repository_identity"
        ]
      },
      "minItems": 0,
      "uniqueItems": true
    },
    "update_policy": {
      "anyOf": [
        {
          "enum": [
            "upgrade",
            "security",
            "security-minimal",
            "exact-replay"
          ]
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "format",
    "action",
    "operation_id",
    "plan_digest",
    "dry_run",
    "accept_system_changes",
    "accept_grafts",
    "allow_source_builds",
    "selections",
    "update_policy"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "action": {
            "const": "stop"
          }
        }
      },
      "then": {
        "properties": {
          "operation_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "action": {
            "enum": [
              "continue",
              "manual",
              "salvage",
              "activate"
            ]
          },
          "dry_run": {
            "const": false
          }
        }
      },
      "then": {
        "properties": {
          "plan_digest": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          }
        }
      }
    }
  ]
}
