{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/eddiethedean/ontocode/docs/lsp-protocol.schema.json",
  "title": "OntoIndex LSP protocol (v0.8)",
  "description": "JSON Schema for ontoindex/* custom LSP method payloads (v0.8). Method routing is documented in lsp-api.md; graph node/edge shapes are partial.",
  "definitions": {
    "EntityKind": {
      "type": "string",
      "enum": [
        "class",
        "object_property",
        "data_property",
        "annotation_property",
        "individual",
        "ontology",
        "other"
      ]
    },
    "PatchEntityKind": {
      "type": "string",
      "enum": [
        "class",
        "object_property",
        "data_property",
        "annotation_property",
        "individual"
      ]
    },
    "PatchOp": {
      "type": "object",
      "required": ["op"],
      "properties": {
        "op": { "type": "string" },
        "entity_iri": { "type": "string" },
        "kind": { "$ref": "#/definitions/PatchEntityKind" },
        "value": { "type": "string" },
        "parent_iri": { "type": "string" },
        "manchester": { "type": "string" }
      },
      "additionalProperties": true
    },
    "EntityAxiomSummary": {
      "type": "object",
      "required": ["kind", "display", "editable"],
      "properties": {
        "kind": { "type": "string" },
        "display": { "type": "string" },
        "manchester": { "type": ["string", "null"] },
        "parent_iri": { "type": ["string", "null"] },
        "editable": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "TabularQueryResult": {
      "type": "object",
      "required": ["columns", "rows"],
      "properties": {
        "columns": {
          "type": "array",
          "items": { "type": "string" }
        },
        "rows": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": { "type": "string" }
          }
        },
        "truncated": { "type": ["boolean", "null"] }
      },
      "additionalProperties": false
    },
    "QueryParams": {
      "type": "object",
      "required": ["sql"],
      "properties": {
        "sql": { "type": "string" }
      },
      "additionalProperties": false
    },
    "SparqlParams": {
      "type": "object",
      "required": ["query"],
      "properties": {
        "query": { "type": "string" }
      },
      "additionalProperties": false
    },
    "ManchesterCompletions": {
      "type": "object",
      "required": ["classes", "object_properties", "data_properties", "datatypes"],
      "properties": {
        "classes": { "type": "array", "items": { "type": "string" } },
        "object_properties": { "type": "array", "items": { "type": "string" } },
        "data_properties": { "type": "array", "items": { "type": "string" } },
        "datatypes": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "ParseManchesterParams": {
      "type": "object",
      "required": ["expression", "axiom_kind"],
      "properties": {
        "expression": { "type": "string" },
        "axiom_kind": { "type": "string" },
        "entity_iri": { "type": ["string", "null"] },
        "document_uri": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "ParseManchesterResult": {
      "type": "object",
      "required": ["normalized", "turtle_fragment", "tree", "diagnostics", "completions"],
      "properties": {
        "normalized": { "type": "string" },
        "turtle_fragment": { "type": "string" },
        "tree": {},
        "diagnostics": { "type": "array" },
        "completions": { "$ref": "#/definitions/ManchesterCompletions" }
      },
      "additionalProperties": false
    },
    "ApplyAxiomPatchParams": {
      "type": "object",
      "required": ["document_uri", "patches"],
      "properties": {
        "document_uri": { "type": "string" },
        "patches": {
          "type": "array",
          "items": { "$ref": "#/definitions/PatchOp" }
        },
        "preview_only": { "type": "boolean", "default": false }
      },
      "additionalProperties": false
    },
    "SubclassEdge": {
      "type": "object",
      "required": ["child", "parent"],
      "properties": {
        "child": { "type": "string" },
        "parent": { "type": "string" }
      },
      "additionalProperties": false
    },
    "ReasonerWarning": {
      "type": "object",
      "required": ["code", "message"],
      "properties": {
        "code": { "type": "string" },
        "message": { "type": "string" },
        "suggested_profile": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "InferredHierarchy": {
      "type": "object",
      "required": ["edges", "unsatisfiable", "combined"],
      "properties": {
        "edges": {
          "type": "array",
          "items": { "$ref": "#/definitions/SubclassEdge" }
        },
        "unsatisfiable": {
          "type": "array",
          "items": { "type": "string" }
        },
        "combined": { "type": "object" }
      },
      "additionalProperties": false
    },
    "ReasonerSnapshot": {
      "type": "object",
      "required": [
        "profile_used",
        "consistent",
        "unsatisfiable",
        "inferred",
        "new_inferences",
        "warnings",
        "duration_ms",
        "classified_at"
      ],
      "properties": {
        "profile_used": { "type": "string" },
        "consistent": { "type": "boolean" },
        "unsatisfiable": {
          "type": "array",
          "items": { "type": "string" }
        },
        "inferred": { "$ref": "#/definitions/InferredHierarchy" },
        "new_inferences": {
          "type": "array",
          "items": { "$ref": "#/definitions/SubclassEdge" }
        },
        "warnings": {
          "type": "array",
          "items": { "$ref": "#/definitions/ReasonerWarning" }
        },
        "duration_ms": { "type": "integer" },
        "classified_at": { "type": "integer" }
      },
      "additionalProperties": false
    },
    "RunReasonerParams": {
      "type": "object",
      "properties": {
        "profile": { "type": "string", "default": "el" },
        "auto_detect": { "type": "boolean", "default": true }
      },
      "additionalProperties": false
    },
    "RunReasonerResult": {
      "type": "object",
      "required": [
        "profile_used",
        "consistent",
        "unsatisfiable",
        "inferred_edge_count",
        "new_inferences",
        "warnings",
        "duration_ms",
        "snapshot"
      ],
      "properties": {
        "profile_used": { "type": "string" },
        "consistent": { "type": "boolean" },
        "unsatisfiable": {
          "type": "array",
          "items": { "type": "string" }
        },
        "inferred_edge_count": { "type": "integer" },
        "new_inferences": {
          "type": "array",
          "items": { "$ref": "#/definitions/SubclassEdge" }
        },
        "warnings": {
          "type": "array",
          "items": { "$ref": "#/definitions/ReasonerWarning" }
        },
        "duration_ms": { "type": "integer" },
        "snapshot": { "$ref": "#/definitions/ReasonerSnapshot" }
      },
      "additionalProperties": false
    },
    "GetExplanationParams": {
      "type": "object",
      "required": ["class_iri"],
      "properties": {
        "class_iri": { "type": "string" },
        "profile": { "type": "string", "default": "el" }
      },
      "additionalProperties": false
    },
    "ExplanationStep": {
      "type": "object",
      "required": ["index", "rule", "display"],
      "properties": {
        "index": { "type": "integer" },
        "rule": { "type": "string" },
        "display": { "type": "string" },
        "subject_iri": { "type": ["string", "null"] },
        "object_iri": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "GetExplanationResult": {
      "type": "object",
      "required": ["class_iri", "steps", "text"],
      "properties": {
        "class_iri": { "type": "string" },
        "steps": {
          "type": "array",
          "items": { "$ref": "#/definitions/ExplanationStep" }
        },
        "text": { "type": "string" }
      },
      "additionalProperties": false
    },
    "DiagnosticSummary": {
      "type": "object",
      "required": ["code", "severity", "message", "file"],
      "properties": {
        "code": { "type": "string" },
        "severity": { "type": "string", "enum": ["error", "warning", "info"] },
        "message": { "type": "string" },
        "file": { "type": "string" },
        "line": { "type": ["integer", "null"] },
        "column": { "type": ["integer", "null"] },
        "entity_iri": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "CatalogSnapshot": {
      "type": "object",
      "required": ["documents", "entities", "hierarchy", "diagnostics"],
      "properties": {
        "documents": { "type": "array" },
        "entities": { "type": "array" },
        "hierarchy": { "type": "object" },
        "diagnostics": {
          "type": "array",
          "items": { "$ref": "#/definitions/DiagnosticSummary" }
        },
        "reasoner": { "$ref": "#/definitions/ReasonerSnapshot" }
      },
      "additionalProperties": true
    },
    "IndexWorkspaceParams": {
      "type": "object",
      "properties": {
        "workspace_uri": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "GetEntityParams": {
      "type": "object",
      "required": ["iri"],
      "properties": {
        "iri": { "type": "string" }
      },
      "additionalProperties": false
    },
    "LspErrorPayload": {
      "type": "object",
      "required": ["code", "message", "recoverable"],
      "properties": {
        "code": { "type": "string" },
        "message": { "type": "string" },
        "recoverable": { "type": "boolean" },
        "user_action": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "UsageSummary": {
      "type": "object",
      "required": ["iri", "referenced_iri", "file", "kind", "context"],
      "properties": {
        "iri": { "type": "string" },
        "referenced_iri": { "type": "string" },
        "file": { "type": "string" },
        "line": { "type": ["integer", "null"] },
        "column": { "type": ["integer", "null"] },
        "kind": { "type": "string" },
        "context": { "type": "string" }
      },
      "additionalProperties": false
    },
    "FindUsagesResult": {
      "type": "object",
      "required": ["usages"],
      "properties": {
        "usages": {
          "type": "array",
          "items": { "$ref": "#/definitions/UsageSummary" }
        }
      },
      "additionalProperties": false
    },
    "RefactorFileChange": {
      "type": "object",
      "required": ["path", "preview_text", "original_text", "hunks"],
      "properties": {
        "path": { "type": "string" },
        "preview_text": { "type": "string" },
        "original_text": { "type": "string" },
        "hunks": { "type": "array" }
      },
      "additionalProperties": true
    },
    "RefactorPlan": {
      "type": "object",
      "required": ["changes"],
      "properties": {
        "changes": {
          "type": "array",
          "items": { "$ref": "#/definitions/RefactorFileChange" }
        },
        "warnings": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": false
    },
    "ApplyRefactorResult": {
      "type": "object",
      "required": ["files_written"],
      "properties": {
        "files_written": { "type": "integer" },
        "reindex_warning": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "RefactorRequest": {
      "oneOf": [
        {
          "type": "object",
          "required": ["kind", "from_iri", "to_iri"],
          "properties": {
            "kind": { "const": "rename_iri" },
            "from_iri": { "type": "string" },
            "to_iri": { "type": "string" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "from_base", "to_base"],
          "properties": {
            "kind": { "const": "migrate_namespace" },
            "from_base": { "type": "string" },
            "to_base": { "type": "string" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "entity_iri", "target_file"],
          "properties": {
            "kind": { "const": "move_entity" },
            "entity_iri": { "type": "string" },
            "target_file": { "type": "string" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["kind", "entity_iris", "output_file"],
          "properties": {
            "kind": { "const": "extract_module" },
            "entity_iris": { "type": "array", "items": { "type": "string" } },
            "output_file": { "type": "string" },
            "leave_stub": { "type": "boolean", "default": false }
          },
          "additionalProperties": false
        }
      ]
    },
    "GetGraphParams": {
      "type": "object",
      "required": ["kind"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": ["class", "property", "import", "neighborhood"]
        },
        "root_iri": { "type": ["string", "null"] },
        "ontology_iri": { "type": ["string", "null"] },
        "include_inferred": { "type": "boolean", "default": false },
        "hide_deprecated": { "type": "boolean", "default": false }
      },
      "additionalProperties": false
    },
    "RunRobotParams": {
      "type": "object",
      "required": ["subcommand"],
      "properties": {
        "subcommand": { "type": "string" },
        "args": { "type": "array", "items": { "type": "string" }, "default": [] },
        "robot_path": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "RunRobotResult": {
      "type": "object",
      "required": ["exit_code", "stdout", "stderr"],
      "properties": {
        "exit_code": { "type": "integer" },
        "stdout": { "type": "string" },
        "stderr": { "type": "string" }
      },
      "additionalProperties": false
    }
  }
}
