{
  "$id": "https://dragoscv.github.io/axiom/schemas/v3/Plan.schema.json",
  "title": "Plan",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "apiVersion": {
      "type": "string",
      "enum": [
        "axiom.codai.ro/v3",
        "axiom.dev/v2"
      ]
    },
    "kind": {
      "type": "string",
      "const": "Plan"
    },
    "name": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
    },
    "intent": {
      "type": "string",
      "maxLength": 2000
    },
    "profile": {
      "default": "default",
      "type": "string",
      "minLength": 1
    },
    "capabilities": {
      "default": [],
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "fs",
          "net",
          "secret",
          "ai",
          "compute",
          "git"
        ]
      }
    },
    "artifacts": {
      "minItems": 1,
      "maxItems": 2000,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1024,
            "description": "Relative POSIX path, NFC, no reserved names"
          },
          "mode": {
            "default": "0644",
            "type": "string",
            "enum": [
              "0644",
              "0755"
            ]
          },
          "op": {
            "default": "create",
            "type": "string",
            "enum": [
              "create",
              "overwrite",
              "delete"
            ]
          },
          "source": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "inline"
                  },
                  "content": {
                    "type": "string",
                    "maxLength": 262144
                  },
                  "encoding": {
                    "default": "utf8",
                    "type": "string",
                    "enum": [
                      "utf8",
                      "base64"
                    ]
                  }
                },
                "required": [
                  "type",
                  "content"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "cas"
                  },
                  "digest": {
                    "type": "string",
                    "pattern": "^sha256:[a-f0-9]{64}$",
                    "description": "sha256:<64 lowercase hex>"
                  }
                },
                "required": [
                  "type",
                  "digest"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "ref"
                  },
                  "uri": {
                    "type": "string",
                    "format": "uri"
                  },
                  "digest": {
                    "type": "string",
                    "pattern": "^sha256:[a-f0-9]{64}$",
                    "description": "sha256:<64 lowercase hex>"
                  }
                },
                "required": [
                  "type",
                  "uri",
                  "digest"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "template"
                  },
                  "emitter": {
                    "type": "string",
                    "minLength": 1
                  },
                  "template": {
                    "type": "string",
                    "minLength": 1
                  },
                  "params": {
                    "default": {},
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {
                      "$ref": "#/$defs/__schema0"
                    }
                  }
                },
                "required": [
                  "type",
                  "emitter",
                  "template"
                ],
                "additionalProperties": false,
                "description": "template source rendered by a registered emitter at compile time"
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "patch"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "unified",
                      "v4a",
                      "search-replace"
                    ]
                  },
                  "preImage": {
                    "anyOf": [
                      {
                        "type": "string",
                        "pattern": "^sha256:[a-f0-9]{64}$",
                        "description": "sha256:<64 lowercase hex>"
                      },
                      {
                        "type": "string",
                        "const": "absent"
                      }
                    ]
                  },
                  "body": {
                    "type": "string",
                    "maxLength": 262144
                  }
                },
                "required": [
                  "type",
                  "format",
                  "preImage",
                  "body"
                ],
                "additionalProperties": false,
                "description": "patch applied at compile time to the pre-image named by its digest"
              }
            ]
          }
        },
        "required": [
          "path"
        ],
        "additionalProperties": false
      }
    },
    "checks": {
      "default": [],
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "predicate": {
            "type": "string",
            "pattern": "^[a-z][a-zA-Z0-9]*\\.[a-zA-Z][a-zA-Z0-9]*$"
          },
          "params": {
            "$ref": "#/$defs/__schema1"
          },
          "severity": {
            "default": "error",
            "type": "string",
            "enum": [
              "error",
              "warn",
              "info"
            ]
          }
        },
        "required": [
          "id",
          "predicate",
          "params"
        ],
        "additionalProperties": false
      }
    },
    "counter": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "metadata": {
      "default": {},
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "$ref": "#/$defs/__schema2"
      }
    }
  },
  "required": [
    "apiVersion",
    "kind",
    "name",
    "intent",
    "artifacts"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema0"
          }
        }
      ]
    },
    "__schema1": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema1"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema1"
          }
        }
      ]
    },
    "__schema2": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema2"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/$defs/__schema2"
          }
        }
      ]
    }
  }
}
