{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "ai.stravica.knowledge.research/gates.schema.json",
  "title": "Research human-gate queue",
  "description": "gates.json at sessions/<sessionId>/gates.json — the retry queue for human-gated fetches (build-spec §6). Merges brief §3 status-tracking fields with spec §6 descriptive fields. Validator: src/store/gates.mjs.",
  "type": "object",
  "additionalProperties": false,
  "required": ["queue"],
  "properties": {
    "queue": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "url", "gateType", "whatIsNeeded", "status", "blockedAt"],
        "properties": {
          "id": { "type": "string", "minLength": 1, "description": "Gate record id (unique within the session)." },
          "url": { "type": "string", "minLength": 1, "description": "The gated URL." },
          "gateType": { "type": "string", "description": "e.g. cloudflare, captcha, auth, paywall." },
          "subQuestionId": { "type": "string", "description": "Which sub-question was blocked, if known." },
          "whatIsNeeded": { "type": "string", "description": "Human-readable what-is-needed-to-clear (spec §6). Also the brief's `reason`." },
          "status": {
            "type": "string",
            "enum": ["pending", "retrying", "resolved", "failed"],
            "description": "pending → retrying (marked eligible by `gates --retry`) → resolved/failed."
          },
          "blockedAt": { "type": "string", "description": "ISO 8601 UTC when the gate was hit (spec's loggedAt)." },
          "resolution": { "type": "string", "description": "Note or outcome once resolved/failed." },
          "artifactPath": { "type": "string", "description": "Path to the saved page content (sessions/<id>/gated/<hash>.md, spec §6.4)." }
        }
      }
    }
  }
}
