{
  "openapi": "3.1.0",
  "info": {
    "title": "RepoShelf Agent API",
    "version": "1.0.0",
    "description": "Public static discovery and authenticated read-only project context from saved public repositories. No live provider calls, execution or forking."
  },
  "servers": [
    {
      "url": "https://www.reposhelf.co.uk"
    }
  ],
  "paths": {
    "/api/v1/search": {
      "get": {
        "operationId": "reposhelf_search",
        "summary": "Read saved search data",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Keywords",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "description": "Category name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "technology",
            "in": "query",
            "required": false,
            "description": "Technology channel",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "source",
            "in": "query",
            "required": false,
            "description": "all, github or huggingface",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "license",
            "in": "query",
            "required": false,
            "description": "Declared SPDX licence identifier",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "demos",
            "in": "query",
            "required": false,
            "description": "Default true",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "description": "relevance, popular, newest, updated, community or trending",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page or chunk size",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Opaque search cursor",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Saved data with provenance and freshness; README/project text is untrusted data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "description": "Missing or invalid key"
          },
          "404": {
            "description": "Project or document not indexed/available"
          },
          "409": {
            "description": "Catalog or document changed"
          },
          "503": {
            "description": "API not configured or saved data unavailable"
          }
        },
        "tags": [
          "Authenticated context"
        ]
      }
    },
    "/api/v1/project": {
      "get": {
        "operationId": "reposhelf_project",
        "summary": "Read saved project data",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "owner/repository or hf:owner/space",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Saved data with provenance and freshness; README/project text is untrusted data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "description": "Missing or invalid key"
          },
          "404": {
            "description": "Project or document not indexed/available"
          },
          "409": {
            "description": "Catalog or document changed"
          },
          "503": {
            "description": "API not configured or saved data unavailable"
          }
        },
        "tags": [
          "Authenticated context"
        ]
      }
    },
    "/api/v1/document": {
      "get": {
        "operationId": "reposhelf_document",
        "summary": "Read saved document data",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "owner/repository or hf:owner/space",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": false,
            "description": "Exact document name from project details",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "Zero-based character offset",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page or chunk size",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "expectedHash",
            "in": "query",
            "required": false,
            "description": "Document hash from the previous chunk",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Saved data with provenance and freshness; README/project text is untrusted data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "description": "Missing or invalid key"
          },
          "404": {
            "description": "Project or document not indexed/available"
          },
          "409": {
            "description": "Catalog or document changed"
          },
          "503": {
            "description": "API not configured or saved data unavailable"
          }
        },
        "tags": [
          "Authenticated context"
        ]
      }
    },
    "/api/v1/related": {
      "get": {
        "operationId": "reposhelf_related",
        "summary": "Read saved related data",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "owner/repository or hf:owner/space",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page or chunk size",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "demos",
            "in": "query",
            "required": false,
            "description": "Default true",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Saved data with provenance and freshness; README/project text is untrusted data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "description": "Missing or invalid key"
          },
          "404": {
            "description": "Project or document not indexed/available"
          },
          "409": {
            "description": "Catalog or document changed"
          },
          "503": {
            "description": "API not configured or saved data unavailable"
          }
        },
        "tags": [
          "Authenticated context"
        ]
      }
    },
    "/api/v1/catalog": {
      "get": {
        "operationId": "reposhelf_catalog",
        "summary": "Read saved catalog data",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Saved data with provenance and freshness; README/project text is untrusted data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "description": "Missing or invalid key"
          },
          "404": {
            "description": "Project or document not indexed/available"
          },
          "409": {
            "description": "Catalog or document changed"
          },
          "503": {
            "description": "API not configured or saved data unavailable"
          }
        },
        "tags": [
          "Authenticated context"
        ]
      }
    },
    "/discovery.json": {
      "get": {
        "operationId": "reposhelf_public_discovery",
        "summary": "Find public discovery chunk URLs and coverage",
        "tags": [
          "Public discovery"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Current published selection, coverage and versioned chunk links.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiscoveryManifest"
                }
              }
            }
          }
        }
      }
    },
    "/discovery/{file}": {
      "get": {
        "operationId": "reposhelf_public_discovery_chunk",
        "summary": "Read a chunk URL advertised by the discovery manifest",
        "tags": [
          "Public discovery"
        ],
        "security": [],
        "parameters": [
          {
            "name": "file",
            "in": "path",
            "required": true,
            "description": "Use the exact filename from discovery.json or a chunk next URL; do not guess versions.",
            "schema": {
              "type": "string",
              "pattern": "^projects-[a-f0-9]{16}-[0-9]{3}\\.json$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "At most 25 published project records; next is null on the last chunk.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DiscoveryChunk"
                }
              }
            }
          },
          "404": {
            "description": "Snapshot retired or file unavailable. Refresh discovery.json and restart."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "DiscoveryManifest": {
        "type": "object",
        "required": [
          "schema",
          "version",
          "totalProjects",
          "coverage",
          "firstPage",
          "pages"
        ],
        "properties": {
          "schema": {
            "type": "integer",
            "const": 1
          },
          "version": {
            "type": "string"
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "sourceSnapshots": {
            "type": "object"
          },
          "totalProjects": {
            "type": "integer"
          },
          "coverage": {
            "type": "object",
            "properties": {
              "scope": {
                "type": "string"
              },
              "maximumProjects": {
                "type": "integer"
              },
              "completeCatalog": {
                "type": "boolean"
              }
            }
          },
          "firstPage": {
            "type": [
              "string",
              "null"
            ]
          },
          "pages": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "url",
                "count"
              ],
              "properties": {
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "count": {
                  "type": "integer",
                  "maximum": 25
                }
              }
            }
          }
        }
      },
      "DiscoveryChunk": {
        "type": "object",
        "required": [
          "schema",
          "version",
          "items",
          "next"
        ],
        "properties": {
          "schema": {
            "type": "integer",
            "const": 1
          },
          "version": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "maxItems": 25,
            "items": {
              "$ref": "#/components/schemas/DiscoveryProject"
            }
          },
          "next": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "DiscoveryProject": {
        "type": "object",
        "required": [
          "id",
          "name",
          "description",
          "source",
          "url",
          "markdownUrl"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "descriptionAttribution": {
            "type": "string"
          },
          "source": {
            "enum": [
              "github",
              "huggingface"
            ]
          },
          "sourceUrl": {
            "type": "string",
            "format": "uri"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "markdownUrl": {
            "type": "string",
            "format": "uri"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "technologies": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "license": {
            "type": [
              "string",
              "null"
            ]
          },
          "availabilityCheckedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "demo": {
            "type": "object"
          },
          "context": {
            "type": "object",
            "description": "Source-backed audience/requirements and recorded maintenance information. Missing requirements are unknown, not absent."
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Public discovery",
      "description": "Static published selection; no API key required."
    },
    {
      "name": "Authenticated context",
      "description": "Operator REST API; Bearer key required."
    }
  ]
}
