{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mfeflow.github.io/mfeflow/schema/mfeflow.json",
  "title": "mfeflow.json",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string"
    },
    "version": {
      "const": 1
    },
    "cli": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$"
    },
    "repo": {
      "enum": [
        "platform",
        "shell",
        "remote"
      ]
    },
    "topology": {
      "enum": [
        "monorepo",
        "polyrepo",
        "hybrid"
      ]
    },
    "packageManager": {
      "enum": [
        "pnpm",
        "npm"
      ]
    },
    "scope": {
      "type": "string",
      "pattern": "^@[a-z0-9][a-z0-9-._]*$"
    },
    "apps": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9]*(?:_[a-z][a-z0-9]*)*$"
      },
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "properties": {
          "kind": {
            "enum": [
              "shell",
              "remote"
            ]
          },
          "path": {
            "type": "string"
          },
          "port": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          }
        },
        "required": [
          "kind",
          "path"
        ]
      }
    },
    "features": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^(@[a-z0-9-]+\\/)?[a-z][a-z0-9-]*$"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string"
          },
          "options": {
            "type": "object"
          },
          "integrity": {
            "type": "string",
            "pattern": "^sha256-[0-9a-f]{64}$"
          }
        },
        "required": [
          "version"
        ]
      }
    },
    "files": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^(?![A-Za-z]:)(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+(?:\\/(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+)*$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^sha256-[0-9a-f]{64}$"
      }
    },
    "kept": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^(?![A-Za-z]:)(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+(?:\\/(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+)*$"
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^sha256-[0-9a-f]{64}$"
      }
    },
    "envKeys": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^(?![A-Za-z]:)(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+(?:\\/(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+)*$"
      },
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string",
          "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
        }
      }
    },
    "registries": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^@[a-z0-9][a-z0-9-]*$",
        "not": {
          "const": "@mfeflow"
        }
      },
      "additionalProperties": {
        "type": "string",
        "pattern": "^(?:https:\\/\\/|http:\\/\\/(?:127\\.0\\.0\\.1|localhost|\\[::1\\])(?:[:/?#])).*\\{name\\}"
      }
    },
    "local": {
      "type": "string",
      "pattern": "^(?:(?![A-Za-z]:)(?:\\.\\.(?:\\/\\.\\.)*(?:\\/(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+)*|(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+(?:\\/(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+)*)|(?:\\/|[A-Za-z]:\\/)(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+(?:\\/(?!\\.\\.?(?:\\/|$))[^/\\\\\\u0000]+)*)$"
    },
    "budget": {
      "type": "object",
      "properties": {
        "shellKb": {
          "type": "number",
          "minimum": 1
        },
        "remoteKb": {
          "type": "number",
          "minimum": 1
        },
        "lcpDeltaMs": {
          "type": "number",
          "minimum": 1
        },
        "baselineKb": {
          "type": "number",
          "minimum": 1
        }
      }
    },
    "registry": {
      "type": "object",
      "properties": {
        "host": {
          "type": "string",
          "pattern": "^(?:file:\\S.*|s3:\\/\\/[a-z0-9][a-z0-9.-]{1,61}[a-z0-9](?:\\/\\S*)?)$"
        },
        "baseUrl": {
          "type": "string",
          "pattern": "^(?:https://[^@\\s?#]*[^/@\\s?#]|http://(?:127\\.0\\.0\\.1|localhost|\\[::1\\])(?::\\d+)?(?:/[^@\\s?#]*[^/@\\s?#])?)$"
        }
      }
    }
  },
  "required": [
    "version",
    "topology",
    "packageManager",
    "scope",
    "apps",
    "features"
  ]
}
