{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.unoplat.io/schemas/custom-framework-lib-schema-v4.json",
  "title": "Code-Confluence Multi-Language Library Feature Schema v4",
  "description": "Framework / library feature signatures grouped by programming language using capability-operation hierarchy.",
  "type": "object",
  "propertyNames": {
    "$ref": "#/$defs/languageEnum"
  },
  "patternProperties": {
    "^[a-z]+$": {
      "$ref": "#/$defs/languageBlock"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "languageEnum": {
      "type": "string",
      "description": "Allowed lower-case language identifiers.",
      "enum": [
        "python",
        "javascript",
        "typescript",
        "java",
        "go"
      ]
    },
    "languageBlock": {
      "type": "object",
      "description": "All libraries / frameworks implemented in a single language.",
      "patternProperties": {
        "^.+$": {
          "$ref": "#/$defs/libraryDef"
        }
      },
      "additionalProperties": false
    },
    "libraryDef": {
      "type": "object",
      "required": [
        "docs_url",
        "capabilities"
      ],
      "properties": {
        "docs_url": {
          "type": "string",
          "format": "uri",
          "description": "Canonical documentation URL."
        },
        "description": {
          "type": "string",
          "description": "Human-readable description of the library."
        },
        "version": {
          "type": "string",
          "description": "Library version used to verify patterns (optional)."
        },
        "capabilities": {
          "type": "object",
          "minProperties": 1,
          "description": "Discoverable capabilities keyed by capability family.",
          "propertyNames": {
            "$ref": "#/$defs/capabilityFamilyEnum"
          },
          "patternProperties": {
            "^.+$": {
              "$ref": "#/$defs/capabilityDef"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "capabilityFamilyEnum": {
      "type": "string",
      "description": "Allowed canonical capability family identifiers.",
      "enum": [
        "rest_api",
        "graphql_api",
        "rpc_server",
        "websocket_server",
        "sse_server",
        "webhook_receiver",
        "webhook_sender",
        "cli_command",
        "scheduler",
        "background_worker",
        "file_watcher",
        "mqtt_server",
        "tcp_server",
        "udp_server",
        "http_client",
        "graphql_client",
        "rpc_client",
        "websocket_client",
        "email_service",
        "message_broker",
        "job_queue",
        "change_data_capture",
        "relational_database",
        "document_database",
        "key_value_store",
        "wide_column_store",
        "graph_database",
        "multi_model_database",
        "vector_store",
        "file_storage",
        "object_storage",
        "authentication",
        "authorization",
        "configuration",
        "secret_management",
        "observability",
        "telemetry",
        "logging",
        "llm_inference",
        "mcp_server",
        "mcp_client",
        "data_model",
        "web_component"
      ]
    },
    "capabilityDef": {
      "type": "object",
      "required": [
        "operations"
      ],
      "properties": {
        "description": {
          "type": "string",
          "description": "Human-readable description of the capability."
        },
        "operations": {
          "type": "object",
          "minProperties": 1,
          "description": "Discoverable operations keyed by contributor-chosen identifier.",
          "patternProperties": {
            "^.+$": {
              "$ref": "#/$defs/operationDef"
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "operationDef": {
      "type": "object",
      "required": [
        "description",
        "absolute_paths",
        "target_level",
        "concept"
      ],
      "properties": {
        "description": {
          "type": "string",
          "description": "Human-readable explanation of the operation."
        },
        "docs_url": {
          "type": "string",
          "format": "uri",
          "description": "Operation-specific documentation URL (optional)."
        },
        "absolute_paths": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "description": "Fully-qualified symbols identifying the constructor / base class / annotation provider.",
          "items": {
            "type": "string",
            "pattern": "^(?:@?[A-Za-z_][\\w-]*)(?:[./:][A-Za-z_][\\w-]*)*\\.[A-Za-z_][\\w]*$"
          }
        },
        "target_level": {
          "$ref": "#/$defs/targetLevelEnum"
        },
        "concept": {
          "$ref": "#/$defs/conceptEnum"
        },
        "construct_query": {
          "$ref": "#/$defs/constructQueryDef"
        },
        "base_confidence": {
          "type": "number",
          "minimum": 0.0,
          "maximum": 1.0,
          "description": "Contributor-authored confidence for CallExpression operation definitions only; lower values indicate higher ambiguity and should include disambiguation guidance in notes."
        },
        "startpoint": {
          "type": "boolean",
          "description": "Indicates whether this operation represents a starting point or entry point in the application, such as API endpoints (e.g., FastAPI routes) or message consumers (e.g., Kafka listeners).",
          "default": false
        },
        "notes": {
          "type": "string",
          "description": "Contributor notes, caveats, links."
        }
      },
      "additionalProperties": false,
      "allOf": [
        {
          "if": {
            "properties": {
              "concept": {
                "const": "CallExpression"
              }
            }
          },
          "then": {
            "properties": {
              "target_level": {
                "const": "function"
              }
            },
            "required": [
              "base_confidence"
            ]
          }
        },
        {
          "if": {
            "properties": {
              "concept": {
                "const": "CallExpression"
              },
              "base_confidence": {
                "type": "number",
                "exclusiveMaximum": 0.7
              }
            },
            "required": [
              "concept",
              "base_confidence"
            ]
          },
          "then": {
            "required": [
              "notes"
            ],
            "properties": {
              "notes": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "concept": {
                "not": {
                  "const": "CallExpression"
                }
              }
            },
            "required": [
              "concept"
            ]
          },
          "then": {
            "not": {
              "required": [
                "base_confidence"
              ]
            }
          }
        },
        {
          "if": {
            "properties": {
              "concept": {
                "const": "Inheritance"
              }
            }
          },
          "then": {
            "properties": {
              "target_level": {
                "const": "class"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "concept": {
                "const": "FunctionDefinition"
              }
            }
          },
          "then": {
            "properties": {
              "target_level": {
                "const": "function"
              }
            }
          }
        }
      ]
    },
    "targetLevelEnum": {
      "type": "string",
      "enum": [
        "function",
        "class"
      ],
      "description": "Granularity of the code element that owns the operation."
    },
    "conceptEnum": {
      "type": "string",
      "enum": [
        "AnnotationLike",
        "CallExpression",
        "Inheritance",
        "FunctionDefinition"
      ],
      "description": "Language-agnostic construct category."
    },
    "constructQueryDef": {
      "type": "object",
      "description": "Optional refinements to the auto-generated Tree-sitter query. Allowed keys depend on the operation's concept.",
      "properties": {
        "method_regex": {
          "type": "string"
        },
        "annotation_name_regex": {
          "type": "string"
        },
        "attribute_regex": {
          "type": "string"
        },
        "callee_regex": {
          "type": "string"
        },
        "superclass_regex": {
          "type": "string"
        },
        "function_name_regex": {
          "type": "string"
        },
        "export_name_regex": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  }
}
