{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://leji.org/schemas/v1.0/context-index.schema.json",
  "title": "Leji context index",
  "description": "Generated map of the context layer. Never hand-maintained; regenerate on change.",
  "type": "object",
  "required": [
    "schemaVersion",
    "generatedAt",
    "rootPath",
    "entries"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "description": "Optional pointer to this schema, for editor validation and tooling.",
      "type": "string"
    },
    "schemaVersion": {
      "description": "The Leji spec line this artifact was written against, e.g. \"1.0\".",
      "type": "string",
      "pattern": "^\\d+\\.\\d+$"
    },
    "generatedAt": {
      "description": "ISO 8601 timestamp when the index was generated.",
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}[T ].+$"
    },
    "generator": {
      "description": "The tool that generated this index.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "name": {
          "description": "Name of the generating tool, e.g. \"leji\".",
          "type": "string"
        },
        "version": {
          "description": "Version of the generating tool.",
          "type": "string"
        }
      }
    },
    "rootPath": {
      "description": "Context root the entries are relative to; mirrors the manifest's rootPath.",
      "type": "string",
      "pattern": "^(?!/)(?!\\./)(?!.*(^|/)\\.\\.(/|$))(?!.*\\\\).*$"
    },
    "entries": {
      "description": "One entry per indexed document in the context layer.",
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "path",
          "title",
          "category"
        ],
        "additionalProperties": false,
        "properties": {
          "id": {
            "description": "Stable identifier; renames and moves update the path, never the id.",
            "type": "string",
            "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
          },
          "path": {
            "description": "Repository-root-relative path to the document.",
            "type": "string",
            "pattern": "^(?!/)(?!\\./)(?!.*(^|/)\\.\\.(/|$))(?!.*\\\\).+$"
          },
          "title": {
            "description": "Human-readable title, from the document's first heading or frontmatter.",
            "type": "string",
            "minLength": 1
          },
          "category": {
            "description": "Which content category this document belongs to.",
            "enum": [
              "domain",
              "system",
              "practice",
              "governance",
              "decisions"
            ]
          },
          "summary": {
            "description": "One-line summary of the document, for routing and navigation.",
            "type": "string"
          },
          "tags": {
            "description": "Optional free-form tags.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "owners": {
            "description": "Optional owners of this document.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "lastModified": {
            "description": "ISO 8601 date the document last changed, from version control where available.",
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2}([T ].*)?$"
          },
          "contentHash": {
            "description": "Hash of the document's contents, used to detect drift and stable moves.",
            "type": "string"
          },
          "freshness": {
            "description": "Review horizon for this document.",
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "reviewAfter": {
                "description": "ISO 8601 date after which the document should be reviewed for staleness.",
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              }
            }
          },
          "links": {
            "description": "Optional outbound references from this document.",
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}
