{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Learner Rules Schema",
  "description": "Schema for opencode-kit learner behavior rules",
  "type": "object",
  "required": ["_meta", "enforcement", "extraction_patterns", "knowledge_persistence"],
  "properties": {
    "_meta": {
      "type": "object",
      "properties": {
        "extends": { "type": ["string", "null"] },
        "version": { "type": "string" },
        "overrides": { "type": "array", "items": { "type": "string" } },
        "appends": { "type": "array", "items": { "type": "string" } },
        "excludes": { "type": "array", "items": { "type": "string" } }
      },
      "required": ["extends"]
    },
    "description": { "type": "string" },
    "version": { "type": "string" },
    "enforcement": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "description": { "type": "string" },
          "severity": { "type": "string", "enum": ["CRITICAL", "HIGH", "MEDIUM", "LOW"] },
          "condition": { "type": "string" },
          "action": { "type": "string" },
          "allowed_tools": { "type": "array", "items": { "type": "string" } },
          "blocked_tools": { "type": "array", "items": { "type": "string" } },
          "violation_action": { "type": "string", "enum": ["BLOCKED", "WARN", "RETRY"] }
        }
      }
    },
    "extraction_patterns": {
      "type": "object",
      "properties": {
        "code_patterns": {
          "type": "object",
          "properties": {
            "description": { "type": "string" },
            "patterns": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": { "type": "string" },
                  "name": { "type": "string" },
                  "detect": { "type": "string" },
                  "extract": { "type": "string" }
                },
                "required": ["id", "name", "detect", "extract"]
              }
            }
          }
        },
        "architecture_patterns": {
          "type": "object",
          "properties": {
            "description": { "type": "string" },
            "patterns": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": { "type": "string" },
                  "name": { "type": "string" },
                  "detect": { "type": "string" },
                  "extract": { "type": "string" }
                },
                "required": ["id", "name", "detect", "extract"]
              }
            }
          }
        }
      }
    },
    "knowledge_persistence": {
      "type": "object",
      "properties": {
        "storage": {
          "type": "object",
          "properties": {
            "primary": { "type": "string" },
            "fallback": { "type": "string" }
          }
        },
        "categories": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": { "type": "string" },
              "description": { "type": "string" },
              "key_format": { "type": "string" },
              "ttl": { "type": "string" }
            },
            "required": ["id", "description", "key_format", "ttl"]
          }
        }
      }
    },
    "rules": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "severity": { "type": "string", "enum": ["CRITICAL", "HIGH", "MEDIUM", "LOW"] },
          "desc": { "type": "string" },
          "condition": { "type": "string" },
          "action": { "type": "string" }
        },
        "required": ["id", "severity", "desc", "condition", "action"]
      }
    }
  }
}