{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "/schemas/chroma/chroma.schema.json",
  "title": "Chroma app manifest",
  "description": "Project manifest read by the Chroma CLI (chroma dev, chroma build) and browser loaders (plugins/loader.js). Derived from Chroma/cli/examples/*/chroma.json and CLI field access in cli/chroma.sh.",
  "type": "object",
  "additionalProperties": false,
  "required": ["name", "mode"],
  "properties": {
    "name": {
      "type": "string",
      "description": "Project name; also used as the output archive name when package.zip is true."
    },
    "mode": {
      "type": "string",
      "enum": ["static", "dynamic"],
      "description": "Selects the build path: static minifies files individually; dynamic bundles with esbuild."
    },
    "entry": {
      "type": "string",
      "default": "index.html",
      "description": "Path to the HTML entry file."
    },
    "outDir": {
      "type": "string",
      "default": "dist",
      "description": "Build output directory."
    },
    "plugins": {
      "type": "array",
      "description": "Plugin folder ids vendored under plugins/ and loaded by plugins/loader.js.",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "engine": {
      "$ref": "#/$defs/engine"
    },
    "build": {
      "$ref": "#/$defs/build"
    },
    "package": {
      "$ref": "#/$defs/package"
    },
    "dev": {
      "$ref": "#/$defs/dev"
    }
  },
  "$defs": {
    "engine": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "vendorDir": {
          "type": "string",
          "default": "pkg",
          "description": "Directory containing the vendored WASM engine pkg/ output."
        },
        "rebuildWasm": {
          "type": "boolean",
          "default": false,
          "description": "When true (dynamic builds), recompile the engine from source before bundling."
        }
      }
    },
    "build": {
      "type": "object",
      "description": "Mode-specific build settings. Static builds use scripts/styles; dynamic builds use jsEntry/outfile.",
      "additionalProperties": false,
      "properties": {
        "scripts": {
          "type": "array",
          "description": "JavaScript files to minify individually (static mode).",
          "items": { "type": "string", "minLength": 1 }
        },
        "styles": {
          "type": "array",
          "description": "CSS files to minify individually (static mode).",
          "items": { "type": "string" }
        },
        "jsEntry": {
          "type": "string",
          "description": "Entry module for the esbuild bundle (dynamic mode)."
        },
        "outfile": {
          "type": "string",
          "default": "bundle.js",
          "description": "Bundled output filename (dynamic mode)."
        },
        "format": {
          "type": "string",
          "enum": ["esm"],
          "description": "Bundle format recorded in templates; CLI always passes --format=esm to esbuild."
        },
        "minify": {
          "type": "boolean",
          "description": "Documented in templates; CLI minifies via esbuild --minify."
        },
        "sourcemap": {
          "type": "boolean",
          "description": "Documented in templates for build output metadata."
        }
      }
    },
    "package": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "zip": {
          "type": "boolean",
          "description": "When true, zip (or tar.gz) the build output after bundling (dynamic mode)."
        }
      }
    },
    "dev": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "port": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65535,
          "default": 4173,
          "description": "Default port for chroma dev (overridable with --port)."
        },
        "desktop": {
          "type": "boolean",
          "default": false,
          "description": "When true and mode is dynamic, chroma dev opens Chroma Desktop in develop mode."
        }
      }
    }
  },
  "allOf": [
    {
      "if": { "properties": { "mode": { "const": "static" } }, "required": ["mode"] },
      "then": {
        "properties": {
          "build": {
            "anyOf": [
              { "required": ["scripts"] },
              { "not": { "required": ["jsEntry"] } }
            ]
          }
        }
      }
    },
    {
      "if": { "properties": { "mode": { "const": "dynamic" } }, "required": ["mode"] },
      "then": {
        "properties": {
          "build": {
            "required": ["jsEntry"]
          }
        }
      }
    }
  ]
}
