{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "CacheSphere Context Pack",
  "description": "Schema for compact agent context packs used by CacheSphere to reduce prompt overhead.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "version",
    "title",
    "summary",
    "kind",
    "status",
    "languageIds",
    "stackIds",
    "toolIds",
    "projectTypes",
    "requirements",
    "tags",
    "tokenBudget",
    "agentUse",
    "projectShape",
    "idioms",
    "gotchas",
    "examples",
    "evidenceLinks"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "title": {
      "type": "string",
      "minLength": 3
    },
    "summary": {
      "type": "string",
      "minLength": 20
    },
    "kind": {
      "type": "string",
      "enum": ["agent-memory", "build-pack", "decision-pack", "starter-pack"]
    },
    "status": {
      "type": "string",
      "enum": ["draft", "review", "stable"]
    },
    "languageIds": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
      },
      "uniqueItems": true
    },
    "stackIds": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
      },
      "uniqueItems": true
    },
    "toolIds": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
      },
      "uniqueItems": true
    },
    "projectTypes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 2
      },
      "uniqueItems": true
    },
    "requirements": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 3
      },
      "uniqueItems": true
    },
    "tags": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 2
      },
      "uniqueItems": true
    },
    "tokenBudget": {
      "type": "object",
      "additionalProperties": false,
      "required": ["compactTokens", "fullTokens"],
      "properties": {
        "compactTokens": {
          "type": "integer",
          "minimum": 1
        },
        "fullTokens": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "agentUse": {
      "type": "object",
      "additionalProperties": false,
      "required": ["whenToUse", "avoidIf", "systemPromptAddendum"],
      "properties": {
        "whenToUse": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        },
        "avoidIf": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        },
        "systemPromptAddendum": {
          "type": "string",
          "minLength": 20
        }
      }
    },
    "projectShape": {
      "type": "object",
      "additionalProperties": false,
      "required": ["files", "commands"],
      "properties": {
        "files": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 2
          },
          "uniqueItems": true
        },
        "commands": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 2
          },
          "uniqueItems": true
        }
      }
    },
    "idioms": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 3
      },
      "uniqueItems": true
    },
    "gotchas": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 3
      },
      "uniqueItems": true
    },
    "examples": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["title", "prompt", "output"],
        "properties": {
          "title": { "type": "string", "minLength": 3 },
          "prompt": { "type": "string", "minLength": 10 },
          "output": { "type": "string", "minLength": 10 }
        }
      }
    },
    "evidenceLinks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["label", "href"],
        "properties": {
          "label": { "type": "string", "minLength": 2 },
          "href": { "type": "string", "minLength": 3 }
        }
      }
    },
    "token_estimate": {
      "type": "number",
      "description": "Estimated token count when this pack is used in an agent prompt"
    },
    "compact_summary": {
      "type": "string",
      "maxLength": 150,
      "description": "Ultra-compact summary (≤150 tokens) optimized for agent context windows"
    },
    "recommended_for_agents": {
      "type": "boolean",
      "description": "Whether this pack is specifically recommended for AI agent use"
    },
    "notes": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 3
      }
    }
  }
}
