{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://bespokeai/spec/bespoke-v0.schema.json",
  "title": "bespoke.yaml v0",
  "type": "object",
  "additionalProperties": false,
  "required": ["spec", "id", "name", "tagline", "summary", "category", "kind", "licence", "source", "stack", "size", "runtime", "data", "adaptation"],
  "$defs": {
    "level": { "enum": ["settings", "extend", "code"] },
    "difficulty": { "enum": ["easy", "moderate", "advanced"] },
    "url": { "type": "string", "pattern": "^https?://" },
    "nonEmpty": { "type": "string", "minLength": 1 }
  },
  "properties": {
    "spec": { "const": "bespoke/v0" },
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{1,48}$" },
    "name": { "$ref": "#/$defs/nonEmpty" },
    "pack_revision": { "type": "integer", "minimum": 2 },
    "pack_guide_version": { "type": "string", "pattern": "^v[1-9][0-9]*$" },
    "tagline": { "type": "string", "minLength": 10, "maxLength": 90 },
    "summary": { "type": "string", "minLength": 40, "maxLength": 600 },
    "category": { "enum": ["money", "tasks-focus", "notes-journal", "food-home", "family", "health-fitness", "learning", "hobbies", "small-business", "community", "ai"] },
    "tags": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
    "kind": { "enum": ["web-app"] },
    "licence": {
      "type": "object", "additionalProperties": false, "required": ["spdx", "summary"],
      "properties": {
        "spdx": { "type": "string", "pattern": "^[A-Za-z0-9.+-]+$" },
        "summary": { "$ref": "#/$defs/nonEmpty" }
      }
    },
    "source": {
      "type": "object", "additionalProperties": false, "required": ["repo", "ref"],
      "properties": {
        "repo": { "type": "string", "pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$" },
        "ref": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
        "homepage": { "$ref": "#/$defs/url" },
        "docs": { "$ref": "#/$defs/url" }
      }
    },
    "demo": {
      "type": "object", "additionalProperties": false, "required": ["url"],
      "properties": {
        "url": { "$ref": "#/$defs/url" },
        "credentials": { "type": "string" },
        "notes": { "type": "string" }
      }
    },
    "stack": {
      "type": "object", "additionalProperties": false, "required": ["languages"],
      "properties": {
        "languages": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "frameworks": { "type": "array", "items": { "type": "string" } },
        "databases": { "type": "array", "items": { "type": "string" } }
      }
    },
    "size": {
      "type": "object", "additionalProperties": false, "required": ["difficulty"],
      "properties": {
        "difficulty": { "$ref": "#/$defs/difficulty" },
        "notes": { "type": "string" }
      }
    },
    "runtime": {
      "type": "object", "additionalProperties": false, "required": ["modes", "quickstart"],
      "properties": {
        "modes": { "type": "array", "minItems": 1, "items": { "enum": ["hosted-demo", "docker", "local-dev", "static-host", "server", "desktop", "mobile"] } },
        "quickstart": { "$ref": "#/$defs/nonEmpty" },
        "trial_quickstart": { "$ref": "#/$defs/nonEmpty" },
        "requirements": { "type": "array", "items": { "type": "string" } },
        "dev": { "type": "string" },
        "test": { "type": "string" },
        "build": { "type": "string" },
        "lint": { "type": "string" },
        "ports": { "type": "array", "items": { "type": "integer" } }
      }
    },
    "agent_files": { "type": "array", "items": { "type": "string" } },
    "services": {
      "type": "array",
      "items": {
        "type": "object", "additionalProperties": false, "required": ["name", "required", "purpose"],
        "properties": {
          "name": { "type": "string" },
          "required": { "type": "boolean" },
          "cost": { "type": "string" },
          "purpose": { "type": "string" }
        }
      }
    },
    "env": {
      "type": "array",
      "items": {
        "type": "object", "additionalProperties": false, "required": ["key", "required", "description"],
        "properties": {
          "key": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
          "required": { "type": "boolean" },
          "secret": { "type": "boolean" },
          "description": { "type": "string" }
        }
      }
    },
    "data": {
      "type": "object", "additionalProperties": false, "required": ["personal_data"],
      "properties": {
        "personal_data": { "type": "boolean" },
        "storage": { "type": "string" },
        "notes": { "type": "string" }
      }
    },
    "adaptation": {
      "type": "object", "additionalProperties": false, "required": ["knobs", "suggested"],
      "properties": {
        "knobs": {
          "type": "array", "minItems": 1,
          "items": {
            "type": "object", "additionalProperties": false, "required": ["id", "level", "where", "description"],
            "properties": {
              "id": { "type": "string", "pattern": "^[a-z0-9-]+$" },
              "level": { "$ref": "#/$defs/level" },
              "where": { "type": "string" },
              "description": { "type": "string" }
            }
          }
        },
        "suggested": {
          "type": "array", "minItems": 1,
          "items": {
            "type": "object", "additionalProperties": false, "required": ["id", "title", "level", "difficulty", "prompt"],
            "properties": {
              "id": { "type": "string", "pattern": "^[a-z0-9-]+$" },
              "title": { "type": "string" },
              "level": { "$ref": "#/$defs/level" },
              "difficulty": { "$ref": "#/$defs/difficulty" },
              "prompt": { "type": "string" }
            }
          }
        },
        "do_not_break": { "type": "array", "items": { "type": "string" } },
        "upstream_friendly": { "type": "string" }
      }
    },
    "media": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "logo": { "type": "string" },
        "screenshots": { "type": "array", "items": { "type": "string" } }
      }
    },
    "listing": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "audience": { "type": "string" },
        "highlights": { "type": "array", "items": { "type": "string" } },
        "aliases": { "type": "array", "items": { "type": "string" }, "description": "Everyday phrases people may search for, such as 'split bills'." }
      }
    },
    "hosting": {
      "type": "object", "additionalProperties": false,
      "description": "Where a non-technical user can run the app: third-party cloud partners (handoff/partners.yaml), a free official web version, or their own device.",
      "properties": {
        "cloud": { "type": "array", "items": { "type": "object", "additionalProperties": false, "required": ["partner", "price"],
          "properties": { "partner": { "type": "string" }, "app": { "type": "string" }, "price": { "type": "string" } } } },
        "free_web": { "type": "object", "additionalProperties": false, "required": ["url", "note"], "properties": { "url": { "$ref": "#/$defs/url" }, "note": { "type": "string" } } },
        "local": { "type": "object", "additionalProperties": false, "required": ["kind"], "properties": { "kind": { "enum": ["docker", "desktop", "appliance"] }, "note": { "type": "string" } } },
        "public_ok": { "type": "boolean", "description": "false when the app has no login by default, so a cloud copy must be protected first." }
      }
    },
    "safety": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "notes": { "type": "array", "items": { "type": "string" } },
        "last_scan": { "type": "string" }
      }
    }
  }
}
