{
  "openapi": "3.1.0",
  "info": {
    "title": "Shop Inventory API",
    "version": "1.2.0",
    "description": "Private shop inventory. Agents: POST /agent/request (no auth) -> owner approves in the web UI Agents tab -> GET /agent/pickup/{id} with the saved pickup secret to receive the session token once -> compact /a/* endpoints. Full guide: /agents.md"
  },
  "servers": [
    {
      "url": "https://shop.whydidimakethat.com"
    }
  ],
  "externalDocs": {
    "description": "Agent guide (markdown)",
    "url": "https://shop.whydidimakethat.com/agents.md"
  },
  "tags": [
    {
      "name": "discovery",
      "description": "Public, no auth"
    },
    {
      "name": "onboarding",
      "description": "Public agent access request + token pickup"
    },
    {
      "name": "agent",
      "description": "Compact API for approved agent sessions"
    },
    {
      "name": "admin",
      "description": "Owner (master token) only; agents never use these"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "discovery"
        ],
        "operationId": "health",
        "summary": "Liveness probe",
        "security": [],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "service": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/agents.md": {
      "get": {
        "tags": [
          "discovery"
        ],
        "operationId": "agentGuide",
        "summary": "Agent onboarding guide (markdown)",
        "security": [],
        "responses": {
          "200": {
            "description": "markdown",
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/llms.txt": {
      "get": {
        "tags": [
          "discovery"
        ],
        "operationId": "llmsTxt",
        "summary": "llms.txt index",
        "security": [],
        "responses": {
          "200": {
            "description": "text",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "tags": [
          "discovery"
        ],
        "operationId": "openapi",
        "summary": "This document",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 JSON",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/agent/request": {
      "post": {
        "tags": [
          "onboarding"
        ],
        "operationId": "requestAccess",
        "summary": "Request agent access (public, no authentication)",
        "description": "Creates a pending request for the owner to approve. Response includes `pickup`, a secret shown ONLY ONCE: save it privately. Idempotent: while a matching request is pending (or approved but undelivered) a repeat call returns the existing request with `existing:1` and no `pickup`. Matching = same Idempotency-Key/`key` if given, else same name+purpose+scopes. Request `read` for lookup; add `claim` only to reserve gear; `suggest`/`edit` only to add or correct items.",
        "security": [],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Optional. Same key while open => same request returned (existing:1)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AccessRequest"
              },
              "example": {
                "a": "my-agent",
                "p": "equipment lookup",
                "s": [
                  "read"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Request created (or existing returned)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccessRequestResult"
                }
              }
            }
          },
          "400": {
            "description": "bad_json or missing agent name `a`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/agent/pickup/{id}": {
      "get": {
        "tags": [
          "onboarding"
        ],
        "operationId": "pickupToken",
        "summary": "Check approval status / pick up the session token (once)",
        "description": "Authenticate with the pickup secret from /agent/request via X-Pickup or Authorization: Bearer. After owner approval the first call returns the session `token` exactly once; later calls return `delivered:1`.",
        "security": [
          {
            "pickupHeader": []
          },
          {
            "pickupBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PickupResult"
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid pickup secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "404": {
            "description": "unknown request id (err: nf)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/a/items": {
      "get": {
        "tags": [
          "agent"
        ],
        "operationId": "listItems",
        "summary": "Search items (compact)",
        "description": "Scope: read.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search name/brand/model/notes/id"
          },
          {
            "name": "c",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact category"
          },
          {
            "name": "l",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            },
            "description": "Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ItemList"
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "createItem",
        "summary": "Add an item (scope edit = saved now; suggest = waits for owner approval)",
        "description": "Scope: edit or suggest. `n` required; `id` optional (default: slug of brand + model, else of the name). 409 `exists` if the id is taken, `duplicate` if the same brand+model is listed (send `distinct: true` if it is really a different item), `pending` if the same add is already waiting. Every add is logged and the owner can undo it.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "n"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "optional item id (lowercase, digits, dashes)"
                  },
                  "distinct": {
                    "type": "boolean"
                  },
                  "n": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "name (alias: name)"
                  },
                  "b": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "brand (alias: brand)"
                  },
                  "m": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "model / part number (alias: model)"
                  },
                  "c": {
                    "type": "string",
                    "maxLength": 60,
                    "description": "category (alias: category), e.g. consumable, tool, machine, electronics, hardware, shop-equipment, other"
                  },
                  "q": {
                    "type": "number",
                    "minimum": 0,
                    "description": "owned quantity (alias: quantity)"
                  },
                  "u": {
                    "type": "string",
                    "maxLength": 20,
                    "description": "unit (alias: unit), default ea"
                  },
                  "loc": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "location (alias: location)"
                  },
                  "cond": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "condition (alias: condition)"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 300,
                    "description": "why (shown to the owner with the change)"
                  },
                  "review": {
                    "type": "boolean",
                    "description": "true: queue for owner approval even with edit scope"
                  },
                  "key": {
                    "type": "string",
                    "description": "idempotency key (or Idempotency-Key header)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "added (edit)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": 1
                    },
                    "ch": {
                      "type": "string"
                    },
                    "st": {
                      "const": "applied"
                    },
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "queued for the owner (suggest)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": 1
                    },
                    "ch": {
                      "type": "string"
                    },
                    "st": {
                      "const": "pending"
                    },
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "409": {
            "description": "exists / duplicate / pending",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/a/items/{id}": {
      "get": {
        "tags": [
          "agent"
        ],
        "operationId": "getItem",
        "summary": "One item with held claims",
        "description": "Scope: read.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ItemDetail"
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "404": {
            "description": "nf",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "agent"
        ],
        "operationId": "patchItem",
        "summary": "Correct an item (scope edit = saved now; suggest = waits for owner approval)",
        "description": "Scope: edit or suggest. Send only the fields to change. Quantity can't go below what claims hold. Every edit is logged with before/after and the owner can undo it.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "n": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "name (alias: name)"
                  },
                  "b": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "brand (alias: brand)"
                  },
                  "m": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "model / part number (alias: model)"
                  },
                  "c": {
                    "type": "string",
                    "maxLength": 60,
                    "description": "category (alias: category), e.g. consumable, tool, machine, electronics, hardware, shop-equipment, other"
                  },
                  "q": {
                    "type": "number",
                    "minimum": 0,
                    "description": "owned quantity (alias: quantity)"
                  },
                  "u": {
                    "type": "string",
                    "maxLength": 20,
                    "description": "unit (alias: unit), default ea"
                  },
                  "loc": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "location (alias: location)"
                  },
                  "cond": {
                    "type": "string",
                    "maxLength": 120,
                    "description": "condition (alias: condition)"
                  },
                  "notes": {
                    "type": "string",
                    "maxLength": 2000
                  },
                  "note": {
                    "type": "string",
                    "maxLength": 300,
                    "description": "why (shown to the owner with the change)"
                  },
                  "review": {
                    "type": "boolean",
                    "description": "true: queue for owner approval even with edit scope"
                  },
                  "key": {
                    "type": "string",
                    "description": "idempotency key (or Idempotency-Key header)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "applied, pending or unchanged",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": 1
                    },
                    "ch": {
                      "type": "string"
                    },
                    "st": {
                      "type": "string",
                      "enum": [
                        "applied",
                        "pending",
                        "unchanged"
                      ]
                    },
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "404": {
            "description": "nf",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "409": {
            "description": "below_held",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/a/claims": {
      "get": {
        "tags": [
          "agent"
        ],
        "operationId": "listClaims",
        "summary": "Held claims (own session; all for master)",
        "description": "Scope: read or claim.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "p",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Project label filter"
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "i": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ClaimRow"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/a/claim": {
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "claimItem",
        "summary": "Reserve stock for a project (does not change owned quantity)",
        "description": "Scope: claim.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "item id"
                  },
                  "q": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 1
                  },
                  "p": {
                    "type": "string",
                    "maxLength": 80,
                    "description": "project label"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "claimed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": 1
                    },
                    "cid": {
                      "type": "string"
                    },
                    "aq": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "404": {
            "description": "nf",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "409": {
            "description": "no_stock (includes aq)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/a/release": {
      "post": {
        "tags": [
          "agent"
        ],
        "operationId": "releaseClaim",
        "summary": "Release a held claim",
        "description": "Scope: claim. Provide `cid`, or `id` (+ optional `p`) for your latest held claim.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "cid": {
                    "type": "string"
                  },
                  "id": {
                    "type": "string"
                  },
                  "p": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "released",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "const": 1
                    },
                    "aq": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope or forbidden (not your claim)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "404": {
            "description": "nf",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          },
          "409": {
            "description": "already",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/a/changes": {
      "get": {
        "tags": [
          "agent"
        ],
        "operationId": "listMyChanges",
        "summary": "Your item adds/edits and their status (pending, applied, rejected, undone)",
        "description": "Scope: read, suggest or edit.",
        "security": [
          {
            "agentSession": []
          },
          {
            "agentTokenHeader": []
          },
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "st",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "applied",
                "rejected",
                "undone"
              ]
            }
          },
          {
            "name": "l",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "i": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequiredCompact"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompactError"
                }
              }
            }
          }
        }
      }
    },
    "/admin/changes": {
      "get": {
        "tags": [
          "admin"
        ],
        "operationId": "adminListChanges",
        "summary": "Agent item changes for review (owner only)",
        "security": [
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "st",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "applied",
                "rejected",
                "undone",
                "all"
              ],
              "default": "pending"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequired"
                }
              }
            }
          }
        }
      }
    },
    "/admin/changes/{id}/{action}": {
      "post": {
        "tags": [
          "admin"
        ],
        "operationId": "adminDecideChange",
        "summary": "Approve or reject a suggested change, or undo an applied one (owner only)",
        "description": "Undo refuses when the item changed again since (send {\"force\": true} to restore anyway), when claims hold stock, or (for an added item) when purchases reference it.",
        "security": [
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "approve",
                "reject",
                "undo"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequired"
                }
              }
            }
          },
          "409": {
            "description": "not_pending / not_applied / conflict / exists / has_claims / has_purchases"
          }
        }
      }
    },
    "/admin/sessions": {
      "get": {
        "tags": [
          "admin"
        ],
        "operationId": "adminListSessions",
        "summary": "List agent sessions (owner/master token only)",
        "security": [
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "st",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "active",
                "denied",
                "revoked"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequired"
                }
              }
            }
          }
        }
      }
    },
    "/admin/sessions/{id}/approve": {
      "post": {
        "tags": [
          "admin"
        ],
        "operationId": "adminApprove",
        "summary": "Approve a pending request (owner only). Does not return the token; the agent picks it up.",
        "security": [
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "s": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "read",
                        "claim",
                        "suggest",
                        "edit"
                      ]
                    }
                  },
                  "days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 3650,
                    "default": 365
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "approved"
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequired"
                }
              }
            }
          },
          "404": {
            "description": "not_found"
          },
          "409": {
            "description": "not_pending"
          }
        }
      }
    },
    "/admin/sessions/{id}/deny": {
      "post": {
        "tags": [
          "admin"
        ],
        "operationId": "adminDeny",
        "summary": "Deny a pending request (owner only)",
        "security": [
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "denied"
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequired"
                }
              }
            }
          }
        }
      }
    },
    "/admin/sessions/{id}/revoke": {
      "post": {
        "tags": [
          "admin"
        ],
        "operationId": "adminRevoke",
        "summary": "Revoke a session (owner only)",
        "security": [
          {
            "masterBearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "revoked"
          },
          "401": {
            "description": "Missing/invalid/expired credentials. Body points at /agents.md and the public request endpoint.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthRequired"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "agentSession": {
        "type": "http",
        "scheme": "bearer",
        "description": "Agent session token (ag_…) obtained once from GET /agent/pickup/{id} after owner approval."
      },
      "agentTokenHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Agent-Token",
        "description": "Alternative to Authorization: Bearer for the agent session token."
      },
      "pickupHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Pickup",
        "description": "Pickup secret (pk_…) returned once by POST /agent/request."
      },
      "pickupBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Pickup secret (pk_…) as bearer, for /agent/pickup/{id} only."
      },
      "masterBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Owner master API token. Agents never receive this."
      }
    },
    "schemas": {
      "AccessRequest": {
        "type": "object",
        "required": [
          "a"
        ],
        "properties": {
          "a": {
            "type": "string",
            "maxLength": 80,
            "description": "Agent name (alias: agent_name)"
          },
          "p": {
            "type": "string",
            "maxLength": 200,
            "description": "Purpose shown to the owner (alias: purpose)"
          },
          "s": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "read",
                "claim",
                "suggest",
                "edit"
              ]
            },
            "default": [
              "read"
            ],
            "description": "Scopes (alias: scopes). `read` = lookup; `claim` = reserve gear; `suggest` = propose item adds/edits for owner approval; `edit` = add/edit items directly (logged, owner can undo). Ask for the minimum."
          },
          "key": {
            "type": "string",
            "maxLength": 200,
            "description": "Optional idempotency key (same as Idempotency-Key header)"
          }
        }
      },
      "AccessRequestResult": {
        "type": "object",
        "required": [
          "id",
          "st"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Request/session id (s_…)"
          },
          "st": {
            "type": "string",
            "enum": [
              "pending",
              "active"
            ]
          },
          "pickup": {
            "type": "string",
            "description": "SECRET (pk_…), returned only on first creation. Save privately; never shown again."
          },
          "existing": {
            "const": 1,
            "description": "Present when an open matching request was returned instead of creating a new one (no pickup included)"
          },
          "poll": {
            "type": "string",
            "description": "Path to poll: /agent/pickup/{id}"
          },
          "note": {
            "type": "string"
          }
        }
      },
      "PickupResult": {
        "type": "object",
        "required": [
          "st"
        ],
        "properties": {
          "st": {
            "type": "string",
            "enum": [
              "pending",
              "active",
              "denied",
              "revoked"
            ]
          },
          "token": {
            "type": "string",
            "description": "Session token (ag_…). Delivered exactly once."
          },
          "s": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Granted scopes"
          },
          "delivered": {
            "const": 1,
            "description": "Token was already picked up earlier"
          }
        }
      },
      "AuthRequired": {
        "type": "object",
        "properties": {
          "error": {
            "const": "authentication_required"
          },
          "agent_docs": {
            "const": "/agents.md"
          },
          "request_access": {
            "type": "object",
            "properties": {
              "method": {
                "const": "POST"
              },
              "path": {
                "const": "/agent/request"
              },
              "authentication_required": {
                "const": false
              }
            }
          }
        }
      },
      "AuthRequiredCompact": {
        "type": "object",
        "properties": {
          "err": {
            "type": "string",
            "enum": [
              "authentication_required",
              "missing_pickup",
              "invalid_pickup"
            ]
          },
          "agent_docs": {
            "const": "/agents.md"
          },
          "request_access": {
            "$ref": "#/components/schemas/AuthRequired/properties/request_access"
          }
        }
      },
      "CompactError": {
        "type": "object",
        "properties": {
          "err": {
            "type": "string"
          },
          "aq": {
            "type": "integer"
          },
          "need": {
            "type": "string"
          },
          "m": {
            "type": "string"
          }
        }
      },
      "Item": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "n": {
            "type": "string",
            "description": "name"
          },
          "b": {
            "type": "string",
            "description": "brand"
          },
          "m": {
            "type": "string",
            "description": "model"
          },
          "c": {
            "type": "string",
            "description": "category"
          },
          "q": {
            "type": "integer",
            "description": "owned quantity"
          },
          "aq": {
            "type": "integer",
            "description": "available = owned - held"
          },
          "loc": {
            "type": "string",
            "description": "location"
          }
        }
      },
      "ItemList": {
        "type": "object",
        "properties": {
          "i": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Item"
            }
          },
          "n": {
            "type": "integer"
          }
        }
      },
      "ItemDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Item"
          },
          {
            "type": "object",
            "properties": {
              "h": {
                "type": "integer",
                "description": "held quantity"
              },
              "cl": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "cid": {
                      "type": "string"
                    },
                    "q": {
                      "type": "integer"
                    },
                    "p": {
                      "type": "string"
                    },
                    "a": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "ClaimRow": {
        "type": "object",
        "properties": {
          "cid": {
            "type": "string"
          },
          "id": {
            "type": "string",
            "description": "item id"
          },
          "n": {
            "type": "string"
          },
          "q": {
            "type": "integer"
          },
          "p": {
            "type": "string"
          },
          "a": {
            "type": "string"
          },
          "t": {
            "type": "string",
            "description": "created at"
          }
        }
      }
    }
  }
}