{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/git-top/json-schema/git-top-health-response-schema.json",
  "title": "HealthResponse",
  "description": "Health and source-preflight response. Agents should inspect db, metadata.source, sync_freshness, and project counts before trusting recommendations.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/git-top-health-api-openapi.yml#/components/schemas/HealthResponse",
  "type": "object",
  "required": [
    "ok",
    "db",
    "project_count",
    "raw_project_count",
    "knowledge_ready_project_count",
    "sync_health",
    "sync_freshness",
    "metadata"
  ],
  "properties": {
    "ok": {
      "type": "boolean"
    },
    "db": {
      "type": "string",
      "enum": [
        "available",
        "missing",
        "error"
      ]
    },
    "project_count": {
      "type": "integer"
    },
    "raw_project_count": {
      "type": "integer"
    },
    "knowledge_ready_project_count": {
      "type": "integer"
    },
    "sync_health": {
      "type": "string"
    },
    "sync_freshness": {
      "type": "string"
    },
    "last_successful_sync_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "hours_since_successful_sync": {
      "type": [
        "number",
        "null"
      ]
    },
    "operational_storage": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "healthy",
            "warning",
            "critical",
            "unknown"
          ]
        },
        "github_cache_entries": {
          "type": "integer"
        },
        "github_cache_body_bytes": {
          "type": "integer"
        },
        "github_cache_max_entries": {
          "type": "integer"
        },
        "github_cache_retention_entries": {
          "type": "integer"
        },
        "github_cache_body_budget_bytes": {
          "type": "integer"
        },
        "utilization": {
          "type": "number"
        },
        "star_snapshot_count": {
          "type": "integer"
        },
        "sync_run_count": {
          "type": "integer"
        },
        "governance_run_count": {
          "type": "integer"
        },
        "project_change_count": {
          "type": "integer"
        },
        "feedback_proposal_count": {
          "type": "integer"
        }
      }
    },
    "metadata": {
      "$ref": "#/$defs/Metadata"
    }
  },
  "additionalProperties": true,
  "$defs": {
    "Metadata": {
      "type": "object",
      "description": "Common provenance envelope for agent-facing responses. Agents should require source=d1 for high-confidence production claims and disclose seed fallback.",
      "properties": {
        "source": {
          "type": "string",
          "enum": [
            "d1",
            "seed"
          ]
        },
        "reason": {
          "type": "string"
        },
        "project_count": {
          "type": "integer"
        },
        "generated_at": {
          "type": "string",
          "format": "date-time"
        },
        "snapshot_id": {
          "type": "string",
          "description": "Stable identity for the corpus snapshot used by this response."
        },
        "latest_synced_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "schema_version": {
          "type": "string",
          "enum": [
            "git-top.knowledge.v1"
          ]
        },
        "loaded_project_limit": {
          "type": "integer",
          "description": "Maximum D1 knowledge or search-candidate rows loaded into the bounded ranking set when present."
        },
        "truncated": {
          "type": "boolean",
          "description": "Whether the D1-backed ranking or candidate set reached its limit and may omit additional matching rows."
        },
        "candidate_retrieval": {
          "type": "string",
          "enum": [
            "d1_first"
          ],
          "description": "Search-only marker indicating that deterministic filters and broad query matching ran in D1 before TypeScript ranking."
        },
        "candidate_count": {
          "type": "integer",
          "description": "Number of D1 search candidates passed to the authoritative TypeScript filter and ranking stage."
        },
        "candidate_limit": {
          "type": "integer",
          "description": "Maximum number of D1 search candidates passed to the ranking stage."
        },
        "warnings": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Fallback, count, freshness, or trust caveats that agents should account for before citing results."
        }
      }
    }
  }
}