{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "gno://schemas/search-results@1.0",
  "title": "GNO Search Results",
  "description": "Array of search results with metadata",
  "type": "object",
  "required": ["results", "meta"],
  "$defs": {
    "egressLineage": {
      "type": "object",
      "additionalProperties": false,
      "required": ["effectivePolicy", "digest", "sources"],
      "properties": {
        "effectivePolicy": { "enum": ["local_only", "lan", "remote"] },
        "digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "sources": {
          "type": "array",
          "minItems": 1,
          "maxItems": 128,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["collection", "policy", "source"],
            "properties": {
              "collection": {
                "type": "string",
                "pattern": "^[a-z0-9][a-z0-9_-]{0,63}$"
              },
              "policy": { "enum": ["local_only", "lan", "remote"] },
              "source": {
                "enum": ["explicit", "config_default", "legacy_default"]
              }
            }
          }
        }
      }
    },
    "searchResult": {
      "type": "object",
      "required": ["docid", "score", "uri", "snippet", "source"],
      "properties": {
        "docid": {
          "type": "string",
          "description": "Document ID (short hash of source)",
          "pattern": "^#[a-f0-9]{6,8}$"
        },
        "score": {
          "type": "number",
          "description": "Relevance score (0-1 normalized)",
          "minimum": 0,
          "maximum": 1
        },
        "uri": {
          "type": "string",
          "description": "Document URI (gno://collection/path, optionally with ?index= for non-default indexes)",
          "pattern": "^gno://[^/]+/.+(\\?index=[^\\s]+)?$"
        },
        "line": {
          "type": "integer",
          "description": "Best matching/source line (1-indexed)",
          "minimum": 1
        },
        "title": {
          "type": "string",
          "description": "Extracted document title (optional)"
        },
        "contentType": {
          "type": "string",
          "description": "Canonical inferred content type"
        },
        "categories": {
          "type": "array",
          "description": "Category filters associated with the document",
          "items": {
            "type": "string"
          }
        },
        "snippetLanguage": {
          "type": "string",
          "description": "Language of snippet content (BCP-47 or 'und')"
        },
        "context": {
          "type": "string",
          "description": "Resolved user-configured retrieval guidance, ordered from global to collection to matching path prefixes"
        },
        "egressLineage": { "$ref": "#/$defs/egressLineage" },
        "snippet": {
          "type": "string",
          "description": "Matching text snippet from document mirror"
        },
        "record": {
          "type": "object",
          "additionalProperties": false,
          "description": "Bounded logical-record provenance for a file/export source",
          "required": ["recordKey", "sourceLocator", "anchors", "adapter"],
          "properties": {
            "recordKey": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
            "sourceLocator": {
              "type": "string",
              "minLength": 1,
              "maxLength": 512
            },
            "anchors": {
              "type": "array",
              "maxItems": 256,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["kind", "value"],
                "properties": {
                  "kind": {
                    "enum": [
                      "line",
                      "cue",
                      "timestamp",
                      "message",
                      "event",
                      "record"
                    ]
                  },
                  "value": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512
                  },
                  "endValue": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512
                  }
                }
              }
            },
            "adapter": {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "version", "fingerprint"],
              "properties": {
                "id": { "type": "string", "minLength": 1, "maxLength": 128 },
                "version": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
              }
            },
            "author": { "type": "string", "maxLength": 2048 },
            "participants": {
              "type": "array",
              "maxItems": 256,
              "items": { "type": "string", "minLength": 1, "maxLength": 2048 }
            },
            "categories": {
              "type": "array",
              "maxItems": 256,
              "items": { "type": "string", "minLength": 1, "maxLength": 512 }
            },
            "dateFields": {
              "type": "object",
              "maxProperties": 256,
              "propertyNames": { "type": "string", "maxLength": 128 },
              "additionalProperties": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              }
            },
            "messageId": { "type": "string", "maxLength": 2048 },
            "inReplyTo": { "type": "string", "maxLength": 2048 },
            "references": {
              "type": "array",
              "maxItems": 256,
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              }
            },
            "threadId": { "type": "string", "maxLength": 2048 },
            "eventId": { "type": "string", "maxLength": 2048 },
            "sessionId": { "type": "string", "maxLength": 2048 },
            "attachments": {
              "type": "array",
              "maxItems": 256,
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["name"],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 512
                  },
                  "mime": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  },
                  "bytes": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 9007199254740991
                  },
                  "disposition": { "enum": ["inline", "attachment"] },
                  "sha256": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                }
              }
            }
          }
        },
        "snippetRange": {
          "type": "object",
          "description": "Line range of snippet in mirror content",
          "properties": {
            "startLine": {
              "type": "integer",
              "description": "Start line (1-indexed)",
              "minimum": 1
            },
            "endLine": {
              "type": "integer",
              "description": "End line (1-indexed, inclusive)",
              "minimum": 1
            }
          },
          "required": ["startLine", "endLine"]
        },
        "source": {
          "type": "object",
          "description": "Source file metadata",
          "required": ["relPath", "mime", "ext"],
          "properties": {
            "absPath": {
              "type": "string",
              "description": "Absolute filesystem path when resolvable from collection root + relPath. Default field on gno search --json (no --source flag). Omitted when unresolvable; consumers fall back to the URI tail for display and disable file-open."
            },
            "relPath": {
              "type": "string",
              "description": "Path relative to collection root"
            },
            "mime": {
              "type": "string",
              "description": "MIME type of source file"
            },
            "ext": {
              "type": "string",
              "description": "File extension (including dot)",
              "pattern": "^\\.[a-zA-Z0-9]+$"
            },
            "modifiedAt": {
              "type": "string",
              "description": "Last modification time (ISO 8601)",
              "format": "date-time"
            },
            "documentDate": {
              "type": "string",
              "description": "Canonical frontmatter document date (ISO 8601)",
              "format": "date-time"
            },
            "sizeBytes": {
              "type": "integer",
              "description": "File size in bytes",
              "minimum": 0
            },
            "sourceHash": {
              "type": "string",
              "description": "SHA-256 hash of source file"
            }
          }
        },
        "conversion": {
          "type": "object",
          "description": "Conversion metadata",
          "properties": {
            "converterId": {
              "type": "string",
              "description": "Converter identifier (e.g., 'adapter/markitdown-js')"
            },
            "converterVersion": {
              "type": "string",
              "description": "Converter version"
            },
            "mirrorHash": {
              "type": "string",
              "description": "SHA-256 hash of mirror content"
            },
            "warnings": {
              "type": "array",
              "description": "Conversion warnings",
              "items": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "enum": [
                      "LOSSY",
                      "TRUNCATED",
                      "PARTIAL",
                      "UNSUPPORTED_FEATURE",
                      "LOW_CONFIDENCE"
                    ]
                  },
                  "message": {
                    "type": "string"
                  }
                },
                "required": ["code", "message"]
              }
            }
          }
        },
        "tags": {
          "type": "array",
          "description": "Tags associated with the document",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "contentTypeBoost": {
      "type": "object",
      "required": [
        "baseScore",
        "cappedContribution",
        "combinedAuxiliaryApplied",
        "combinedAuxiliaryCap",
        "combinedAuxiliaryRequested",
        "configuredFactor",
        "contentType",
        "finalScore",
        "rawContribution",
        "rawScore",
        "rawScoreKind",
        "ruleSource",
        "rulesFingerprint"
      ],
      "properties": {
        "baseScore": { "type": "number", "minimum": 0, "maximum": 1 },
        "cappedContribution": {
          "type": "number",
          "minimum": -0.05,
          "maximum": 0.05
        },
        "combinedAuxiliaryApplied": {
          "type": "number",
          "minimum": -0.08,
          "maximum": 0.08
        },
        "combinedAuxiliaryCap": { "type": "number", "const": 0.08 },
        "combinedAuxiliaryRequested": { "type": "number" },
        "configuredFactor": { "type": "number", "minimum": 0.5, "maximum": 2 },
        "contentType": { "type": "string" },
        "finalScore": { "type": "number", "minimum": 0, "maximum": 1 },
        "rawContribution": { "type": "number" },
        "rawScore": { "type": "number" },
        "rawScoreKind": {
          "type": "string",
          "enum": ["bm25", "hybrid_blended", "normalized", "vector_distance"]
        },
        "ruleSource": { "type": "string", "enum": ["configured-id", "prefix"] },
        "rulesFingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      },
      "additionalProperties": false
    },
    "explainLine": {
      "type": "object",
      "required": ["stage", "message"],
      "properties": {
        "stage": { "type": "string" },
        "message": { "type": "string" }
      },
      "additionalProperties": false
    },
    "explainResult": {
      "type": "object",
      "required": ["rank", "docid", "score"],
      "properties": {
        "rank": { "type": "integer", "minimum": 1 },
        "docid": { "type": "string", "pattern": "^#[a-f0-9]{6,8}$" },
        "score": { "type": "number" },
        "fusionScore": { "type": "number" },
        "bm25Score": { "type": "number" },
        "vecScore": { "type": "number" },
        "rerankScore": { "type": "number" },
        "projectAffinity": { "type": "object" },
        "contentTypeBoost": { "$ref": "#/$defs/contentTypeBoost" }
      },
      "additionalProperties": false
    }
  },
  "properties": {
    "results": {
      "type": "array",
      "description": "Array of search result items",
      "items": {
        "$ref": "#/$defs/searchResult"
      }
    },
    "meta": {
      "type": "object",
      "description": "Search metadata",
      "required": ["query", "mode", "totalResults"],
      "properties": {
        "warnings": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["code", "message"],
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        },
        "query": {
          "type": "string",
          "description": "Original search query"
        },
        "mode": {
          "type": "string",
          "description": "Search mode used",
          "enum": ["bm25", "vector", "hybrid", "bm25_only"]
        },
        "expanded": {
          "type": "boolean",
          "description": "Whether query expansion was used"
        },
        "reranked": {
          "type": "boolean",
          "description": "Whether reranking was applied"
        },
        "vectorsUsed": {
          "type": "boolean",
          "description": "Whether vector search was used"
        },
        "totalResults": {
          "type": "integer",
          "description": "Total number of results returned",
          "minimum": 0
        },
        "collection": {
          "type": "string",
          "description": "Collection filter if applied"
        },
        "intent": {
          "type": "string",
          "description": "Disambiguating context used to steer retrieval without being searched directly"
        },
        "lang": {
          "type": "string",
          "description": "Language filter/hint if applied"
        },
        "since": {
          "type": "string",
          "description": "Temporal lower bound applied (ISO 8601)",
          "format": "date-time"
        },
        "until": {
          "type": "string",
          "description": "Temporal upper bound applied (ISO 8601)",
          "format": "date-time"
        },
        "categories": {
          "type": "array",
          "description": "Category/content-type filters applied (if any)",
          "items": { "type": "string" }
        },
        "author": {
          "type": "string",
          "description": "Author filter applied (if any)"
        },
        "candidateLimit": {
          "type": "integer",
          "description": "Max candidates sent to reranking (if applicable)",
          "minimum": 1
        },
        "graphExpansion": {
          "type": "object",
          "description": "Bounded one-hop graph retrieval expansion summary",
          "required": [
            "enabled",
            "seedCount",
            "candidateCount",
            "maxCandidates",
            "edgeConfidence",
            "fallbackReasons"
          ],
          "properties": {
            "enabled": {
              "type": "boolean",
              "description": "Whether graph expansion added candidates"
            },
            "seedCount": {
              "type": "integer",
              "minimum": 0,
              "description": "Number of top retrieval seeds used for graph expansion"
            },
            "candidateCount": {
              "type": "integer",
              "minimum": 0,
              "description": "Number of graph neighbors added to the candidate set"
            },
            "maxCandidates": {
              "type": "integer",
              "minimum": 1,
              "description": "Graph candidate cap applied"
            },
            "edgeConfidence": {
              "type": "object",
              "required": ["explicit", "inferred", "ambiguous", "similarity"],
              "properties": {
                "explicit": { "type": "integer", "minimum": 0 },
                "inferred": { "type": "integer", "minimum": 0 },
                "ambiguous": { "type": "integer", "minimum": 0 },
                "similarity": { "type": "integer", "minimum": 0 }
              }
            },
            "fallbackReasons": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Reasons graph expansion did not add candidates, if any"
            }
          }
        },
        "exclude": {
          "type": "array",
          "description": "Explicit exclusion terms applied",
          "items": { "type": "string" }
        },
        "queryLanguage": {
          "type": "string",
          "description": "Detected or overridden query language for prompt selection (typically BCP-47)"
        },
        "queryModes": {
          "type": "object",
          "description": "Summary of structured query modes applied",
          "required": ["term", "intent", "hyde"],
          "properties": {
            "term": {
              "type": "integer",
              "minimum": 0,
              "description": "Number of term mode entries"
            },
            "intent": {
              "type": "integer",
              "minimum": 0,
              "description": "Number of intent mode entries"
            },
            "hyde": {
              "type": "boolean",
              "description": "Whether a hyde entry was provided"
            }
          }
        },
        "tagsAll": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Tags ALL filter applied (if any)"
        },
        "tagsAny": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Tags ANY filter applied (if any)"
        },
        "explain": {
          "type": "object",
          "required": ["lines", "results"],
          "properties": {
            "lines": {
              "type": "array",
              "items": { "$ref": "#/$defs/explainLine" }
            },
            "results": {
              "type": "array",
              "items": { "$ref": "#/$defs/explainResult" }
            }
          },
          "additionalProperties": false
        }
      }
    }
  }
}
