$schema: "https://json-schema.org/draft/2020-12/schema"
title: CodexBlocksIndex
description: >-
  Compiled index of all block-level tags in a fabric. When both spellings of a field are present, both must be valid
  and readers use the current spelling.
type: object
required: [generatedAt, version, stats]
anyOf:
  - required: [threads]
  - required: [strands]
properties:
  generatedAt:
    type: string
    format: date-time
    description: "ISO 8601 timestamp when this index was generated"
  version:
    type: string
    pattern: "^\\d+\\.\\d+\\.\\d+$"
    description: "Schema version for this index format"
  stats:
    type: object
    description: "Aggregate statistics for the block index"
    required: [totalBlocks, totalTags, worthyBlocks]
    anyOf:
      - required: [totalThreads]
      - required: [totalStrands]
    properties:
      totalThreads:
        type: integer
        minimum: 0
        description: "Number of threads with block-level data"
      totalStrands:
        type: integer
        minimum: 0
        deprecated: true
        description: "Deprecated alias for totalThreads."
      totalBlocks:
        type: integer
        minimum: 0
        description: "Total number of blocks across all threads"
      totalTags:
        type: integer
        minimum: 0
        description: "Total number of block-level tags"
      uniqueTags:
        type: integer
        minimum: 0
        description: "Number of unique tags"
      worthyBlocks:
        type: integer
        minimum: 0
        description: "Blocks with worthiness score >= 0.5"
      pendingSuggestions:
        type: integer
        minimum: 0
        description: "Number of blocks with pending tag suggestions"
      tagsBySource:
        type: object
        description: "Tag counts by source"
        properties:
          inline: { type: integer, minimum: 0, description: "Explicit #hashtags in content" }
          nlp: { type: integer, minimum: 0, description: "Vocabulary/TF-IDF extraction" }
          llm: { type: integer, minimum: 0, description: "AI-suggested with reasoning" }
          existing: { type: integer, minimum: 0, description: "Propagated from document" }
          user: { type: integer, minimum: 0, description: "Manually confirmed" }
      blocksByType:
        type: object
        description: "Block counts by type"
        additionalProperties: { type: integer, minimum: 0 }
  tagIndex:
    type: object
    description: "Inverted index: tag -> list of block references"
    additionalProperties:
      type: array
      items:
        type: object
        required: [blockId]
        anyOf:
          - required: [threadPath]
          - required: [strandPath]
        properties:
          threadPath: { type: string }
          strandPath: { type: string, deprecated: true, description: "Deprecated alias for threadPath." }
          blockId: { type: string }
          confidence: { type: number, minimum: 0, maximum: 1 }
  threads:
    $ref: "#/$defs/threads"
    description: "Per-thread block data, keyed by thread path"
  strands:
    $ref: "#/$defs/threads"
    deprecated: true
    description: "Deprecated alias for threads."
$defs:
  threads:
    type: object
    additionalProperties:
      type: object
      required: [path, blockCount, blocks]
      properties:
        path:
          type: string
          description: "Relative path to the thread file"
        title:
          type: string
          description: "Thread title for display"
        blockCount:
          type: integer
          minimum: 0
        tagCount:
          type: integer
          minimum: 0
        worthyBlockCount:
          type: integer
          minimum: 0
        blocks:
          type: array
          description: "All blocks in this thread"
          items:
            type: object
            required: [id, line, type]
            properties:
              id: { type: string }
              line: { type: integer }
              endLine: { type: integer }
              type: { type: string }
              headingLevel: { type: integer }
              headingText: { type: string }
              tags:
                type: array
                items: { type: string }
              suggestedTags:
                type: array
                items:
                  type: object
                  properties:
                    tag: { type: string }
                    confidence: { type: number }
                    source: { type: string }
              worthiness:
                type: object
                properties:
                  score: { type: number }
                  signals:
                    type: object
                    additionalProperties: { type: number }
              extractiveSummary: { type: string }
              warrantsIllustration: { type: boolean }

