{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://humbleteam.local/humble-agents/agent.schema.json",
  "type": "object",
  "required": ["id", "name", "description", "model", "modelClass", "invocation", "authorizationScope", "capabilities", "projectAction", "effects", "grants", "spawnTargets", "queryProfileId", "queryProfileSha256", "permissionDigest", "prompt", "sourcePath"],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
    "name": { "type": "string" },
    "description": { "type": "string" },
    "model": { "enum": ["opus", "fable", "sonnet"] },
    "modelClass": { "enum": ["judgment", "breadth", "execution"] },
    "invocation": { "enum": ["direct", "internal"] },
    "authorizationScope": { "enum": ["project", "studio"] },
    "ownerAgentId": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
    "capabilities": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 }, "uniqueItems": true },
    "projectAction": { "enum": ["read", "write"] },
    "effects": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "enum": ["project-read", "project-write", "repository-read", "repository-write", "safe-command-execution", "web-read", "browser-verification", "figma-read", "figma-write", "agent-spawn"] } },
    "grants": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "oneOf": [
          {
            "type": "object", "additionalProperties": false,
            "required": ["kind", "access", "path", "recursive"],
            "properties": {
              "kind": { "const": "project-path" }, "access": { "const": "write" },
              "path": { "enum": ["brief.md", "ds-tokens.html", "ds-guide.md", "ds-status.md", "artifacts/ads", "artifacts/product", "artifacts/references", "artifacts/3-canvas", "artifacts/7-html-prototype"] },
              "recursive": { "type": "boolean" }
            }
          },
          {
            "type": "object", "additionalProperties": false,
            "required": ["kind", "access", "target"],
            "properties": {
              "kind": { "const": "repository" }, "access": { "const": "read" },
              "target": { "enum": ["root", "learning-file"] }
            }
          },
          {
            "type": "object", "additionalProperties": false,
            "required": ["kind", "access", "target"],
            "properties": {
              "kind": { "const": "repository" }, "access": { "const": "write" },
              "target": { "enum": ["component-paths", "page-paths"] }
            }
          },
          {
            "type": "object", "additionalProperties": false,
            "required": ["kind", "access", "target"],
            "properties": {
              "kind": { "const": "figma" }, "access": { "enum": ["read", "write"] },
              "target": { "enum": ["selection", "frame", "page", "board"] }
            }
          },
          {
            "type": "object", "additionalProperties": false,
            "required": ["kind", "access", "policy"],
            "properties": {
              "kind": { "const": "command" }, "access": { "const": "execute" },
              "policy": { "const": "repository-validation-readonly" }
            }
          }
        ]
      }
    },
    "spawnTargets": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" } },
    "queryProfileId": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]*$" },
    "queryProfileSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "permissionDigest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "prompt": { "type": "string" },
    "sourcePath": { "type": "string" }
  },
  "allOf": [
    {
      "if": { "properties": { "invocation": { "const": "internal" } }, "required": ["invocation"] },
      "then": { "required": ["ownerAgentId"] },
      "else": { "not": { "required": ["ownerAgentId"] } }
    }
  ]
}
