{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://deft.dev/schemas/codebase-map.v1.schema.json",
  "title": "Codebase Map Artifact v1",
  "description": "Language-neutral contract for a provider-emitted codebase-map.v1 artifact. Out-of-process providers may be written in any language, but must emit this JSON object on stdout for Directive to accept it instead of falling back to the default extractor.",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "formatVersion",
    "contractVersion",
    "kind",
    "provider",
    "source",
    "modules",
    "coupling",
    "entryPoints",
    "languageDistribution",
    "degraded"
  ],
  "properties": {
    "formatVersion": {
      "const": "codebase-map.v1",
      "description": "Artifact format version owned by Directive."
    },
    "contractVersion": {
      "const": "codebase-provider.v1",
      "description": "Provider handshake contract version accepted by Directive."
    },
    "kind": {
      "const": "codebase-map",
      "description": "Projection kind."
    },
    "provider": {
      "type": "object",
      "additionalProperties": true,
      "required": ["name"],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string"
        },
        "mode": {
          "type": "string"
        },
        "degraded": {
          "type": "boolean"
        },
        "fallbackReason": {
          "type": "string"
        }
      }
    },
    "source": {
      "type": "object",
      "additionalProperties": true,
      "required": ["projectRoot"],
      "properties": {
        "projectRoot": {
          "type": "string",
          "minLength": 1
        },
        "codeStructurePath": {
          "type": "string"
        },
        "codeStructureHome": {
          "type": ["string", "null"]
        }
      }
    },
    "modules": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["id", "files", "derivedFrom"],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": ["string", "null"]
          },
          "purpose": {
            "type": ["string", "null"]
          },
          "pathGlobs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "fileCount": {
            "type": "integer",
            "minimum": 0
          },
          "files": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "derivedFrom": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    },
    "coupling": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["from", "to", "derivedFrom"],
        "properties": {
          "from": {
            "type": "string",
            "minLength": 1
          },
          "to": {
            "type": "string",
            "minLength": 1
          },
          "derivedFrom": {
            "type": "string",
            "minLength": 1
          },
          "confidence": {
            "type": "string"
          },
          "evidence": {
            "type": "array"
          }
        }
      }
    },
    "entryPoints": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["path", "module", "derivedFrom"],
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1
          },
          "module": {
            "type": "string",
            "minLength": 1
          },
          "derivedFrom": {
            "type": "string",
            "minLength": 1
          },
          "confidence": {
            "type": "string"
          }
        }
      }
    },
    "languageDistribution": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["language", "files", "derivedFrom"],
        "properties": {
          "language": {
            "type": "string",
            "minLength": 1
          },
          "files": {
            "type": "integer",
            "minimum": 0
          },
          "derivedFrom": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "degraded": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "minLength": 1
          },
          "message": {
            "type": "string",
            "minLength": 1
          },
          "module": {
            "type": "string"
          }
        }
      }
    }
  }
}
