openapi: 3.1.0
info:
  title: 1weavr workspace API
  version: 1.0.0-draft
  description: |
    The API behind the dashboard, the browser extension and your own scripts or agents.
    JSON over HTTPS, version 1, under `/api/v1`. **Draft:** this is the designed surface; routes marked
    `x-status: live` exist today, the rest are being built to this shape.
    The marker is checked: a route that exists is marked live, and a route marked live exists.

    ## Design rules
    - **Summaries first, parts on demand.** Lists return small summaries. Heavy or optional parts of one record
      (pictures, console, network, comments, activity) each have their own route under that record, so a view loads
      what is on screen and nothing else. Parts are only nested under the record they belong to.
    - **Cursor pagination.** Every list takes `limit` (1–100, default 25) and `cursor`, and answers
      `{ items, nextCursor }`. `nextCursor` is null on the last page. Cursors are opaque; do not build them.
    - **Filters are query parameters**, repeatable for multi-select (`label=bug&label=copy`). Search is `q`.
    - **Partial updates use PATCH** with only the fields that change. Writes that can race take `If-Match`
      with the record's `etag`; a stale one answers `412`.
    - **Ids are opaque strings.** Items also have a short `ref` for people, headed by their kind: `CAP-128` is a capture.

    ## Security
    Every route except `/health` and `/ready` needs `Authorization: Bearer <token>`. Two kinds of token are accepted:
    a Clerk session JWT (the dashboard) or a personal access key starting `1w_` (the extension, scripts, agents).
    An access key acts as the person who made it, with the role they hold **at the moment of the request**; it never
    has more access than they do. Its scopes narrow that role further: `read` covers every `*.read` permission, `send`
    covers `item.send`, and `write` covers everything else (including your own profile, inbox and keys). A route
    the key's scopes do not cover answers `403 forbidden`. An expired key, a revoked key, and the key of someone who is
    no longer a member answer `401`; removing a member removes their keys.
    A session whose proved email address belongs to an account bound to another sign-in is never joined to that
    account. Where that account cannot be brought up to date from the provider, every route answers
    `409 account_conflict` for that session until an operator has resolved it.

    A token resolves to a principal: a user, one workspace, and a role there. Without `X-Workspace` a session acts in
    the person's own personal workspace (never another person's they were invited into). Send `X-Workspace: <id>` to
    act in another workspace you belong to. Every query is scoped by workspace id, so a record from another workspace answers
    `404`, never `403`, and ids cannot be probed.

    Each operation lists the permission it checks (`x-permission`) and the roles that hold it (`x-roles`). A role says
    what someone may manage in a workspace; what they can do with captures is their seat in the organisation (ADR 0031).

    | Permission | member | admin | owner |
    |---|---|---|---|
    | `item.read`, `comment.read`, `project.read`, `label.read`, `member.read` | ✓ | ✓ | ✓ |
    | `item.write`, `comment.write`, `item.send`, `share.create` | ✓ | ✓ | ✓ |
    | `project.write` (create, rename, archive own and joined projects) | ✓ | ✓ | ✓ |
    | `project.manage` (delete, people on a project) | project lead | ✓ | ✓ |
    | `label.manage`, `member.invite` | if allowed by workspace | ✓ | ✓ |
    | `member.manage`, `connection.manage`, `workspace.manage` | | ✓ | ✓ |
    | `workspace.delete`, role changes to/from owner | | | ✓ |
    | `self.*` (your profile, notifications, inbox, keys, extension) | ✓ | ✓ | ✓ |

    Work also needs a seat that has it: writing, deleting and uploading need `capture`, commenting and sending
    `collaborate`, sharing `share`, managing labels a paid seat. A Viewer seat reads only; refused work answers
    `402 quota` with the seat that would allow it.

    Billing and changing the organisation (`PATCH /organisation`) are no role's: they are the organisation owner's
    (`x-permission: organisation owner`), the person who made the organisation or was handed it, whatever their role in the
    workspace (ADR 0031). An access key never acts as the organisation owner.

    Owners cannot be demoted by admins; the last owner cannot leave or be removed.

    Tracker credentials never leave the server. Pictures are served through signed links (`/a/{asset}?t=…`) and
    short-lived storage URLs; uploads go straight to storage through ten-minute signed slots.

    ## Errors
    Every error is `{ "error": { "code", "message", "details"? } }`. Codes: `unauthenticated` 401, `forbidden` 403,
    `not_found` 404, `conflict` 409, `gone` 410, `precondition_failed` 412, `pending` 428, `invalid` 400/422,
    `quota` 402, `limit` 413, `rate_limited` 429. An unknown cursor or a bad query parameter is `invalid` 400.

    ## Idempotency
    POSTs that create work (sending a capture, filing) take `Idempotency-Key`. A repeat with the same key and body
    replays the first answer with `Idempotent-Replayed: true`; a repeat while the first still runs answers `pending`
    428; the same key with a different body answers `conflict` 409. Keys are per person in a workspace and kept for 24 hours; failed answers are not kept.

    ## Rate limits
    Per client address, per access key and per workspace, in one-minute windows (600 an address, 600 a key, 3000 a
    workspace; the numbers live in `config/plans.json`). Every request counts against its address before the token is
    checked; only a token that verifies counts against its key, so made-up tokens never get an allowance of their own.
    The address is the one our reverse proxy saw, never a forwarded header the client sent. Every answer carries `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset` (seconds).
    A `429` carries `Retry-After`. `x-status: live`.
  contact: { name: Support, email: hello@1weavr.com }
servers:
  - url: https://app.1weavr.com/api/v1
  - url: http://localhost:3000/api/v1
    description: Local development
security:
  - session: []
  - accessKey: []
tags:
  - { name: Onboarding, description: First run and the setup checklist. }
  - { name: Inbox, description: What needs you. Each is for one person and points at an item; open the item and its parts with the Items routes. }
  - { name: Items, description: "Listing, searching, reading and editing items, whatever their kind. An item's parts load separately." }
  - { name: Item parts, description: "Files, comments, activity and filings of one item, each loaded on its own." }
  - { name: Captures, description: "The capture kind: saving one from the extension." }
  - { name: Capture parts, description: "Console, network and actions recorded with one capture, each loaded on its own." }
  - { name: Sharing, description: Shared links to one item. }
  - { name: Projects, description: "Projects, their people and where they send." }
  - { name: Invitations, description: Invite links and email invites. }
  - { name: Members, description: People in the workspace. }
  - { name: Labels, description: Workspace labels shared by every project. }
  - { name: Dev tools, description: 'Development and staging only (DEV_TOOLS=on): the Mail lab, workspace states set through the real code, and what the server runs with.' }
  - { name: Workspace settings, description: "General, sharing, how long files are kept, capture privacy, and deleting the workspace." }
  - { name: Plan and usage }
  - { name: Integrations, description: The app catalogue and connections. Tokens are held server-side only. }
  - { name: Access keys, description: "Personal keys for scripts, the extension and agents." }
  - { name: Profile and preferences, description: "You: profile, notifications, extension settings." }
  - { name: Extension, description: "Routes the browser extension uses: sign-in, config, sync, uploads, the Send menu and sheets, filings, events. Drawing, the dock, voice transcription and the site demo's pins run in the browser and call nothing until Save." }
  - { name: System }

paths:
  # ───────────── System
  /health:
    get:
      tags: [System]
      summary: Liveness
      security: []
      x-status: live
      responses: { '200': { description: Up, content: { application/json: { schema: { type: object, properties: { ok: { type: boolean }, time: { type: integer } } } } } } }
  /ready:
    get:
      tags: [System]
      summary: Readiness (database, storage, queue)
      security: []
      x-status: live
      responses: { '200': { description: Ready }, '503': { description: A dependency is down } }
  /content/{kind}:
    get:
      tags: [System]
      summary: Public site content (changelog, FAQ)
      security: []
      x-status: live
      parameters: [{ name: kind, in: path, required: true, schema: { type: string, enum: [changelog, faq] } }]
      responses: { '200': { description: OK }, '404': { $ref: '#/components/responses/NotFound' } }
  /assets/blob:
    put:
      tags: [System]
      summary: Local blob store upload (only without a bucket)
      description: Exists for the local stack only; with object storage configured it answers 404. Signed upload links point here.
      security: []
      x-status: live
      parameters: [{ name: key, in: query, required: true, schema: { type: string } }]
      requestBody: { content: { application/octet-stream: { schema: { type: string, format: binary } } } }
      responses: { '201': { description: Stored }, '404': { $ref: '#/components/responses/NotFound' } }
    get:
      tags: [System]
      summary: Local blob store download (only without a bucket)
      security: []
      x-status: live
      parameters: [{ name: key, in: query, required: true, schema: { type: string } }]
      responses: { '200': { description: The bytes }, '404': { $ref: '#/components/responses/NotFound' } }
  /me:
    get:
      tags: [Onboarding]
      summary: Who I am, active workspace, role, workspaces
      description: Small and cached. Does not include onboarding, usage or settings; those have their own routes.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Me' } } } }
        '401': { $ref: '#/components/responses/Unauthenticated' }
    delete:
      tags: [Profile and preferences]
      summary: Delete my account
      description: >-
        A signed-in browser session only (an access key answers `403 session_required`), and one that proved who it is
        in the last 10 minutes: otherwise `403 reverification_required`, and the dashboard asks again and retries.
        The JSON body's `confirm` must be the caller's email address, else `invalid`. It travels in the body, never in
        the address (which proxies and access logs keep): a request that carries `?confirm=` is refused as `invalid`
        whatever its body says. Refused with `conflict` while the caller is the
        only owner of a workspace other people are in; `details.workspaces` names them. Workspaces the caller is alone
        in are deleted with them and their storage is emptied in the background; in shared workspaces only the
        caller's membership, access keys and personal choices go, and what they captured stays. Their paid
        subscriptions are stopped and the sign-in account is deleted as the last steps of the same step. `503
        unavailable` means the account is still there and nothing was changed, with two exceptions it names:
        `details.subscriptionsStopped` (workspace names) when a paid plan had already been cancelled at the payment
        provider before the sign-in provider failed, and `details.partial`, where the sign-in is gone and removing
        the data did not finish.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DeleteConfirmation' } } } }
      responses:
        '202': { description: Deleted; storage is emptied in the background }
        '400': { $ref: '#/components/responses/Invalid' }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { description: "`session_required`: called with an access key. `reverification_required`: the session has not proved who it is recently", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '503': { description: "The payment or sign-in provider did not answer; nothing was changed unless `details.subscriptionsStopped` or `details.partial` is set", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }

  # ───────────── Onboarding
  /me/onboarding:
    get:
      tags: [Onboarding]
      summary: Onboarding state and setup checklist
      description: |
        Drives the redirect to Welcome and the "Get set up" strip on the Inbox. Steps are computed on the server from
        real state, so they cannot be faked by the client: `extension` once the caller has collected an extension
        sign-in, `first_item` once they have a live capture here, `invite_team` once the workspace has a second member. `doneAt` is when each first held. `aboutYouDone` once a
        first name and `work` are saved; `practiceDone` once every practice fault is found or the round is skipped.
        `checklistHidden` and the practice choice are per person and per workspace, and so is `guidesEnded`: the
        first-time guides the caller walked to the end or closed with "Don't show again", so one is not shown twice
        on another computer.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Onboarding' } } } }
    patch:
      tags: [Onboarding]
      summary: Save About you, hide the checklist, skip the practice round, end a guide or show the guides again
      description: |
        Only the caller's own state. First and last name and `work` save the caller's profile (as `PATCH /me/profile`).
        `workspaceName` is accepted only from the workspace owner (`403` otherwise) and only during first run, before
        About you is saved (`409` after). `guideEnded` ends one guide for the caller; sending it again changes
        nothing. `guidesReset` shows every guide again. One or the other: both in one change is `400`, and so is a
        guide the server does not know. A refusal writes nothing. Unknown fields and an empty body are `400`.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody:
        content: { application/json: { schema: { $ref: '#/components/schemas/OnboardingPatch' } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Onboarding' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '409': { $ref: '#/components/responses/Conflict' }
  /me/onboarding/practice:
    get:
      tags: [Onboarding]
      summary: The "find what is wrong" practice round
      description: |
        The three faults on the example shop and which ones the caller has found. A fault is found by the caller's
        oldest live capture on the shop (in this workspace) whose title, note or marked element names it, or, for the
        fault that shows in the console, whose console or network entries caught it. `itemId` is that capture.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Practice' } } } }

  # ───────────── Inbox
  /inbox:
    get:
      tags: [Inbox]
      summary: List inbox items (summaries)
      description: |
        One row per event that needs the caller: a mention, an assignment, a comment on their capture, a send, a fix,
        labels added, the first open of their shared link. Never the caller's own doing, and never anyone else's inbox.
        Rows hold only what the list shows. Open the item with `GET /items/{id}` and its parts as needed.
        Newest first. Cleared items and items snoozed into the future are left out; `q` searches the capture title and
        the message. An item whose capture was deleted leaves the list.
      x-permission: self.read
      x-roles: [member, admin, owner]
      x-status: live
      parameters:
        - { name: view, in: query, description: 'Tab: mentions, assigned; everything shows every kind', schema: { type: string, enum: [everything, mentions, assigned], default: everything } }
        - { name: state, in: query, schema: { type: string, enum: [unread, read, all], default: all } }
        - { name: project, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: label, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: actor, in: query, description: User id of who caused the event, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: q, in: query, schema: { type: string, maxLength: 200 } }
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/InboxPage' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
  /inbox/counts:
    get:
      tags: [Inbox]
      summary: Unread counts per view (rail badge and tabs)
      description: Unread items per tab; cleared and snoozed items do not count.
      x-permission: self.read
      x-roles: [member, admin, owner]
      x-status: live
      responses:
        '200': { description: OK, content: { application/json: { schema: { type: object, properties: { everything: { type: integer }, mentions: { type: integer }, assigned: { type: integer } } } } } }
  /inbox/{inboxItemId}:
    parameters: [{ $ref: '#/components/parameters/inboxItemId' }]
    get:
      tags: [Inbox]
      summary: One inbox item
      description: The event and its message text, cleared or snoozed ones included. The capture is referenced, not embedded. Another person's item answers 404.
      x-permission: self.read
      x-roles: [member, admin, owner]
      x-status: live
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/InboxItem' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
    patch:
      tags: [Inbox]
      summary: Mark read or unread, clear (E), or snooze
      description: '`cleared: false` restores a cleared item; `snoozedUntil` must be in the future, and `null` wakes it. Give at least one field: an empty body answers 400. An item deleted meanwhile answers 404.'
      x-permission: self.write
      x-roles: [member, admin, owner]
      x-status: live
      requestBody:
        content: { application/json: { schema: { type: object, properties: { read: { type: boolean }, cleared: { type: boolean }, snoozedUntil: { type: [integer, 'null'] } }, minProperties: 1 } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/InboxItem' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
    delete:
      tags: [Inbox]
      summary: Delete the inbox item
      description: Removes it from the caller's inbox only. The capture is untouched, and the same event does not bring it back.
      x-permission: self.write
      x-roles: [member, admin, owner]
      x-status: live
      responses: { '204': { description: Deleted }, '404': { $ref: '#/components/responses/NotFound' } }
  /inbox/bulk:
    post:
      tags: [Inbox]
      summary: Mark read, unread, clear or delete many
      description: |
        Either explicit `ids` (at most 100; ids that are not the caller's change nothing and are not counted) or `all`
        with the same filters as the list. `all` acts on the caller's newest 5000 items, the same window the list and
        counts read; older ones are left as they are. `changed` counts the items it changed.
      x-permission: self.write
      x-roles: [member, admin, owner]
      x-status: live
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [action]
              properties:
                action: { type: string, enum: [read, unread, clear, delete] }
                ids: { type: array, maxItems: 100, items: { type: string } }
                all:
                  type: object
                  properties:
                    view: { type: string, enum: [everything, mentions, assigned] }
                    state: { type: string, enum: [unread, read, all] }
                    project: { type: array, items: { type: string } }
                    label: { type: array, items: { type: string } }
                    actor: { type: array, items: { type: string } }
                    q: { type: string, maxLength: 200 }
      responses:
        '200': { description: OK, content: { application/json: { schema: { type: object, properties: { changed: { type: integer } } } } } }
        '400': { $ref: '#/components/responses/Invalid' }

  # ───────────── Captures
  /items:
    get:
      tags: [Items]
      summary: List or search items (summaries)
      description: |
        Backs All captures, Mine, Sent to a tool, Shared links (empty until share links are live), the project and label side lists, list and grid views.
        A summary carries one thumbnail URL and counts; it never carries console, network, comments or full pictures.
        `group=page` returns rows ordered by page and a `group` key on each row so the client draws page headers.
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      parameters:
        - { name: scope, in: query, description: '`mine` is captures the caller made, `sent` those sent to a tool, `shared` those with a shared link that is still on (not turned off, not past its expiry).', schema: { type: string, enum: [all, mine, sent, shared], default: all } }
        - { name: kind, in: query, description: 'Only items of these kinds; every kind when left out', schema: { type: array, items: { $ref: '#/components/schemas/ItemKind' } }, style: form, explode: true }
        - { name: project, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: label, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: status, in: query, schema: { type: array, items: { $ref: '#/components/schemas/ItemStatus' } }, style: form, explode: true }
        - { name: createdBy, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: assignee, in: query, description: 'A user id, `me`, or `none` for unassigned', schema: { type: string } }
        - { name: tool, in: query, schema: { type: array, items: { $ref: '#/components/schemas/Tool' } }, style: form, explode: true }
        - { name: pageUrl, in: query, description: 'Exact page or a prefix ending in *', schema: { type: string } }
        - { name: site, in: query, description: Host such as stride.shop (side panel shows this page's site), schema: { type: string } }
        - { name: hasErrors, in: query, description: Only captures with console errors or failed requests, schema: { type: boolean } }
        - { name: since, in: query, schema: { type: integer, description: ms since epoch } }
        - { name: until, in: query, schema: { type: integer } }
        - { name: q, in: query, description: "Searches ref, title, detail, page title and URL", schema: { type: string, maxLength: 200 } }
        - { name: group, in: query, description: "Puts each page's (`page`) or each project's (`project`) captures together, in the sort within it; the response's `groupTotals` counts each group this page shows over the whole list.", schema: { type: string, enum: [none, page, project], default: none } }
        - { name: sort, in: query, schema: { type: string, enum: [newest, oldest, updated], default: newest } }
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ItemPage' } } } }
  /captures:
    post:
      x-changes: 'Pricing v2 (ADR 0031): Refuses a capture past the seat''s monthly allowance, as /sync/push (#425).'
      tags: [Captures]
      summary: Save a whole capture
      description: |
        The capture, its attachments and its labels in one request. Upload each attachment to its slot first (`POST /assets/upload`, then PUT the bytes) and name the asset on the attachment; a capture whose bytes have not all arrived is refused whole.
        `labelIds` are workspace labels; `newLabels` are found by name or made. A label the workspace will not make for the caller is listed in `labelsRefused` and the capture is saved without it.
        The id is the client's. Sending the same id again answers the capture that exists with `created: false` and status 200, so a retry after a lost answer makes nothing new.
        `context.diagnostics` must come with `context.timeline`; the timeline is stored as the capture's console and network parts, credential headers dropped.
        The workspace's capture privacy is enforced here, by saving without rather than refusing: with `keepViewport` off the capture is saved without its viewport attachment (and its thumb) and the upload made for it is removed; with `keepDiagnostics` off it is saved without `context.diagnostics` and without its timeline.
      x-status: live
      x-permission: item.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/CaptureCreate' } } } }
      responses:
        '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/CaptureCreated' } } } }
        '200': { description: The capture already existed, content: { application/json: { schema: { $ref: '#/components/schemas/CaptureCreated' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '400': { $ref: '#/components/responses/Invalid' }
        '403': { description: This role cannot write captures }
        '410': { description: The capture was deleted }
        '413': { description: The request is larger than one capture with a full recording }
        '503': { description: Storage could not be reached; send the same request again }
  /groups/{groupId}:
    parameters: [{ name: groupId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Captures]
      summary: A group of captures
      description: A run of saves (ADR 0026), its name (null until someone names it) and its live items in the order they were saved, each with its `itemGroup` number. 404 for a group of another workspace.
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, required: [id, name, createdAt, items], properties: { id: { type: string }, name: { type: [string, 'null'] }, createdAt: { type: number }, items: { type: array, items: { $ref: '#/components/schemas/ItemSummary' } } } } } } }, '404': { $ref: '#/components/responses/NotFound' } }
    patch:
      tags: [Captures]
      summary: Name a group
      description: Its name, 1 to 120 characters, or null to go back to "Group of N".
      x-status: live
      x-permission: item.write
      x-roles: [member, admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [name], additionalProperties: false, properties: { name: { type: [string, 'null'], minLength: 1, maxLength: 120 } } } } } }
      responses: { '200': { description: Named, content: { application/json: { schema: { type: object, required: [id, name], properties: { id: { type: string }, name: { type: [string, 'null'] } } } } } }, '400': { $ref: '#/components/responses/Invalid' }, '404': { $ref: '#/components/responses/NotFound' } }
  /items/facets:
    get:
      tags: [Items]
      summary: Counts for the side list and filter menus
      x-status: live
      description: >-
        Takes the list's `scope`, `kind`, `project`, `label`, `status`, `createdBy` and `q` filters; answers counts per scope,
        project, label, status and person. Each group is counted under every filter but its own (statuses ignore
        `status`, scopes ignore `scope`), so a choice's count is what `GET /captures` returns with that choice made.
      x-permission: item.read
      x-roles: [member, admin, owner]
      parameters:
        - { name: scope, in: query, schema: { type: string, enum: [all, mine, sent, shared] } }
        - { name: kind, in: query, description: 'Only items of these kinds; every kind when left out', schema: { type: array, items: { $ref: '#/components/schemas/ItemKind' } }, style: form, explode: true }
        - { name: project, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: label, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: status, in: query, schema: { type: array, items: { $ref: '#/components/schemas/ItemStatus' } }, style: form, explode: true }
        - { name: createdBy, in: query, schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { name: q, in: query, schema: { type: string } }
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  scopes: { type: object, additionalProperties: { type: integer } }
                  projects: { type: array, items: { $ref: '#/components/schemas/Count' } }
                  labels: { type: array, items: { $ref: '#/components/schemas/Count' } }
                  statuses: { type: array, items: { $ref: '#/components/schemas/Count' } }
                  people: { type: array, items: { $ref: '#/components/schemas/Count' } }
  /items/{itemId}:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      tags: [Items]
      summary: One capture (the Info tab)
      description: |
        Title, detail, labels, status, assignee, filing, page and environment (address, browser, OS, window, network),
        the marked element, and counts for each part so tabs can show badges. `{itemId}` also accepts the ref (`CAP-128`).
        `prev`/`next` ids follow the list filters passed in the query, for next and previous.
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, headers: { ETag: { schema: { type: string } } }, content: { application/json: { schema: { $ref: '#/components/schemas/ItemView' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
    patch:
      tags: [Items]
      summary: Edit title, detail, labels, status, assignee, project
      x-status: live
      description: Members edit any capture in projects they can see. Moving to another project needs `item.write` in both.
      x-permission: item.write
      x-roles: [member, admin, owner]
      parameters: [{ $ref: '#/components/parameters/ifMatch' }]
      requestBody:
        content: { application/json: { schema: { $ref: '#/components/schemas/ItemPatch' } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ItemView' } } } }
        '412': { $ref: '#/components/responses/Stale' }
    delete:
      tags: [Items]
      summary: Delete a capture and its pictures
      description: The author, or an admin. Signed links already in tools then answer 410.
      x-status: live
      x-permission: item.delete (author) or item.manage (admin)
      x-roles: [member, admin, owner]
      responses: { '204': { description: Deleted } }

  /items/{itemId}/attachments:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      tags: [Item parts]
      summary: The pictures (What you annotated, The whole screen, Where on the page)
      description: Metadata plus a read URL per attachment that stops working at its `expiresAt` (the expiry is signed into the link). Ask with `role` to load only the tab on screen. `size=thumb` links the smaller copy made at capture time, or the original when there is none.
      x-permission: item.read
      x-status: live
      x-roles: [member, admin, owner]
      parameters:
        - { name: role, in: query, schema: { type: array, items: { $ref: '#/components/schemas/AttachmentRole' } }, style: form, explode: true }
        - { name: size, in: query, description: Rendition, schema: { type: string, enum: [thumb, full], default: full } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/AttachmentList' } } } }
  /captures/{captureId}/console:
    parameters: [{ $ref: '#/components/parameters/captureId' }]
    get:
      tags: [Capture parts]
      summary: Console and timeline events (Console tab)
      x-permission: item.read
      x-status: live
      x-roles: [member, admin, owner]
      parameters:
        - { name: level, in: query, schema: { type: array, items: { type: string, enum: [log, info, warn, error, uncaught, unhandledrejection] } }, style: form, explode: true }
        - { name: kind, in: query, description: "Page loads, errors, clicks and keys", schema: { type: array, items: { type: string, enum: [console, navigation, request, click, key] } }, style: form, explode: true }
        - { name: q, in: query, schema: { type: string } }
        - $ref: '#/components/parameters/limitLong'
        - $ref: '#/components/parameters/cursor'
      responses:
        '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/ConsoleEvent' } }, durationMs: { type: integer } } }] } } } }
  /captures/{captureId}/network:
    parameters: [{ $ref: '#/components/parameters/captureId' }]
    get:
      tags: [Capture parts]
      summary: Network requests (Network tab), without bodies
      x-permission: item.read
      x-status: live
      x-roles: [member, admin, owner]
      parameters:
        - { name: failed, in: query, schema: { type: boolean } }
        - { name: type, in: query, schema: { type: array, items: { type: string, enum: [fetch, script, style, image, font, document, other] } }, style: form, explode: true }
        - { name: q, in: query, schema: { type: string } }
        - $ref: '#/components/parameters/limitLong'
        - $ref: '#/components/parameters/cursor'
      responses:
        '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/NetworkRequest' } } } }] } } } }
  /captures/{captureId}/network/{requestId}:
    parameters: [{ $ref: '#/components/parameters/captureId' }, { name: requestId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Capture parts]
      summary: One request's headers and timing, on expand
      description: Authorization, Cookie and Set-Cookie headers are redacted in the extension before upload and never stored.
      x-permission: item.read
      x-status: live
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/NetworkRequestDetail' } } } } }
  /captures/{captureId}/actions:
    parameters: [{ $ref: '#/components/parameters/captureId' }]
    get:
      tags: [Capture parts]
      summary: Actions tab (what can be done here, for the caller)
      description: Whether the caller may edit, send, share or delete. Computed per role; where it can be sent is `GET /send-options`.
      x-permission: item.read
      x-status: live
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/CaptureActions' } } } } }
  /items/{itemId}/comments:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      tags: [Item parts]
      summary: Comments, oldest first
      x-permission: comment.read
      x-status: live
      x-roles: [member, admin, owner]
      parameters: [{ $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/cursor' }]
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/Comment' } } } }] } } } } }
    post:
      tags: [Item parts]
      summary: Comment; @mentions notify and land in inboxes
      description: Mentions are resolved to user ids on the server; only members of the workspace can be mentioned.
      x-permission: comment.write
      x-status: live
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [body], properties: { body: { type: string, minLength: 1, maxLength: 5000 } } } } } }
      responses: { '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/Comment' } } } } }
  /items/{itemId}/comments/{commentId}:
    parameters: [{ $ref: '#/components/parameters/itemId' }, { name: commentId, in: path, required: true, schema: { type: string } }]
    patch:
      tags: [Item parts]
      summary: Edit own comment
      x-permission: comment.write (author only)
      x-status: live
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [body], properties: { body: { type: string, minLength: 1, maxLength: 5000 } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Comment' } } } } }
    delete:
      tags: [Item parts]
      summary: Delete a comment (author or admin)
      x-permission: comment.write (author) or item.manage
      x-status: live
      x-roles: [member, admin, owner]
      responses: { '204': { description: Deleted } }
  /items/{itemId}/activity:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      tags: [Item parts]
      summary: Activity (created, sent, labelled, assigned, fixed, edited), oldest first
      x-permission: item.read
      x-status: live
      x-roles: [member, admin, owner]
      parameters: [{ $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/cursor' }]
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/Activity' } } } }] } } } } }
  /items/{itemId}/prompt:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      x-seat: 'agents'
      tags: [Item parts]
      summary: Copy prompt for a coding agent
      x-status: live
      description: Plain text with the capture's words, signed picture links, console errors and failed requests.
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { text/markdown: { schema: { type: string } } } } }

  # ───────────── Sharing
  /items/{itemId}/shares:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      x-status: live
      tags: [Sharing]
      summary: Shared links to this capture
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { items: { type: array, items: { $ref: '#/components/schemas/Share' } } } } } } } }
    post:
      x-plan: 'link_controls (Business): an audience narrower than the workspace setting, or an expiresAt'
      x-status: live
      tags: [Sharing]
      summary: Make a shared link (Copy link)
      description: Audience defaults to the workspace sharing setting and can only be narrowed, never widened, past it.
      x-permission: share.create
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, properties: { audience: { $ref: '#/components/schemas/ShareAudience' }, expiresAt: { type: [integer, 'null'] }, shows: { type: array, maxItems: 4, items: { $ref: '#/components/schemas/ShareExtra' } } } } } } }
      responses: { '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/Share' } } } } }
  /shares/{shareId}:
    parameters: [{ name: shareId, in: path, required: true, schema: { type: string } }]
    patch:
      x-plan: 'link_controls (Business): changing the audience or setting an expiresAt'
      x-status: live
      tags: [Sharing]
      summary: Change audience, expiry or what the page shows
      x-permission: share.create (maker) or item.manage
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, properties: { audience: { $ref: '#/components/schemas/ShareAudience' }, expiresAt: { type: [integer, 'null'] }, shows: { type: array, maxItems: 4, items: { $ref: '#/components/schemas/ShareExtra' } } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Share' } } } } }
    delete:
      x-status: live
      tags: [Sharing]
      summary: Turn the link off
      x-permission: share.create (maker) or item.manage
      x-roles: [member, admin, owner]
      responses: { '204': { description: Off } }

  # ───────────── Projects
  /projects:
    get:
      x-status: live
      tags: [Projects]
      summary: List projects (the Projects table)
      description: Each row carries counts and up to three people avatars; the full people list is its own route.
      x-permission: project.read
      x-roles: [member, admin, owner]
      parameters:
        - { name: view, in: query, schema: { type: string, enum: [all, mine, archived], default: all } }
        - { name: site, in: query, description: Rank projects that capture on this host first (popup picker), schema: { type: string } }
        - { name: q, in: query, schema: { type: string, maxLength: 120 } }
        - { name: sort, in: query, schema: { type: string, enum: [last_item, recent_for_me, name, items], default: last_item } }
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/ProjectSummary' } } } }] } } } } }
    post:
      x-seat: 'organise'
      x-status: live
      tags: [Projects]
      summary: New project
      x-permission: project.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/ProjectWrite' } } } }
      responses: { '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/Project' } } } }, '409': { description: 'Another live project in the workspace has this name (names are unique, ignoring case and the spaces at the ends).', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } } }
  /projects/{projectId}:
    parameters: [{ $ref: '#/components/parameters/projectId' }]
    get:
      x-status: live
      tags: [Projects]
      summary: One project
      x-permission: project.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Project' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
    patch:
      x-seat: 'organise'
      x-status: live
      tags: [Projects]
      summary: Rename, change sites, archive
      description: Needs `project.write`.
      x-permission: project.write
      x-roles: [member, admin, owner]
      parameters: [{ $ref: '#/components/parameters/ifMatch' }]
      requestBody: { content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/ProjectWrite' }, { properties: { archived: { type: boolean } } }] } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Project' } } } }, '409': { description: 'Another live project in the workspace has the new name.', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }, '412': { $ref: '#/components/responses/Stale' } }
    delete:
      x-seat: 'organise'
      x-status: live
      tags: [Projects]
      summary: Delete a project and its captures
      description: >-
        The JSON body's `confirm` must equal the project name, else `invalid`; a request that carries `?confirm=` is
        refused as `invalid` whatever its body says. Pictures are removed from storage.
      x-permission: project.manage
      x-roles: [admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DeleteConfirmation' } } } }
      responses: { '204': { description: Deleted }, '400': { $ref: '#/components/responses/Invalid' } }
  /projects/{projectId}/stats:
    parameters: [{ $ref: '#/components/parameters/projectId' }]
    get:
      x-status: live
      tags: [Projects]
      summary: Counts (new, fixed, by label) for a period
      x-permission: project.read
      x-roles: [member, admin, owner]
      parameters: [{ name: period, in: query, schema: { type: string, enum: [7d, 30d, all], default: all } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { total: { type: integer }, new: { type: integer }, fixed: { type: integer }, byLabel: { type: array, items: { $ref: '#/components/schemas/Count' } } } } } } } }
  /projects/{projectId}/people:
    parameters: [{ $ref: '#/components/parameters/projectId' }]
    get:
      x-status: live
      tags: [Projects]
      summary: People on a project
      x-permission: project.read
      x-roles: [member, admin, owner]
      parameters: [{ $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/cursor' }]
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/ProjectPerson' } } } }] } } } } }
    post:
      x-status: live
      tags: [Projects]
      summary: Add workspace members to a project
      description: Only existing members. To bring someone new in, use Invitations with a `projectId`.
      x-permission: project.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [userIds], properties: { userIds: { type: array, minItems: 1, maxItems: 50, items: { type: string } }, lead: { type: boolean } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { added: { type: array, items: { type: string } } } } } } } }
  /projects/{projectId}/people/{userId}:
    parameters: [{ $ref: '#/components/parameters/projectId' }, { $ref: '#/components/parameters/userId' }]
    delete:
      x-status: live
      tags: [Projects]
      summary: Take someone off a project
      x-permission: project.manage, or self to leave
      x-roles: [member, admin, owner]
      responses: { '204': { description: Removed } }
  /projects/{projectId}/destination:
    parameters: [{ $ref: '#/components/parameters/projectId' }]
    get:
      x-status: live
      tags: [Projects]
      summary: The project's place (the installation it sends through by default, and where in the tool)
      x-permission: project.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ProjectDestination' } } } } }
    put:
      x-status: live
      tags: [Projects]
      summary: Choose the project's place
      description: >-
        The installation must be one this workspace can send through (active, reaching this project); otherwise
        `400 invalid`. `target` is where in the tool, from the entry's `targets` lookup, or null for none. Without an
        integration runtime on the server this answers 503.
      x-permission: project.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, additionalProperties: false, required: [installationId, target], properties: { installationId: { type: string }, target: { type: [string, 'null'], maxLength: 512 } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ProjectDestination' } } } }, '400': { $ref: '#/components/responses/Invalid' } }
    delete:
      x-status: live
      tags: [Projects]
      summary: Clear the project's place
      x-permission: project.manage
      x-roles: [admin, owner]
      responses: { '204': { description: Cleared } }

  # ───────────── Invitations
  /invitations:
    get:
      x-status: live
      tags: [Invitations]
      summary: Pending invites, by email and by link
      description: Newest first. They carry addresses and working links, so only admins and owners see them. A link invite (`channel` `link`) carries its `note` and its `url` to copy again.
      x-permission: member.manage
      x-roles: [admin, owner]
      parameters: [{ $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/cursor' }]
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/Invitation' } } } }] } } } } }
    post:
      x-status: live
      tags: [Invitations]
      summary: Invite by email (Send N invites)
      description: |
        At most 20 per call and a daily cap per workspace (`invites.perDay` in `config/plans.json`; resends and link invites count too),
        answered with `rate_limited` 429. Each invite carries a `role` here and a `seat`: the seat someone new to the
        organisation gets on joining (someone who already holds one keeps theirs). There is no seat cap: every paid seat is
        billed. Only admins invite as admin, only owners as owner. Members may invite when the invite rules' `adminsOnly`
        is off, with the free `viewer` seat only (a paid one is `403`). Addresses already in the workspace, holding an unexpired invite, or outside the invite rules'
        `allowedDomain` are skipped with a reason. An address whose invite has expired is simply invited again: the
        expired invite is replaced with a fresh code, and the send counts toward the day like any other.
        Each address gets its own code, emailed to it; the invite expires after `invites.emailDays`, and an expired
        invite that is never resent or withdrawn is deleted `invites.expiredKeptDays` after it expired. Optional
        `projectId` (a project of this workspace, otherwise `400 invalid`) adds them to that project on joining.
      x-permission: member.invite
      x-roles: [member (if allowed), admin, owner]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [emails, role, seat]
              properties:
                emails: { type: array, minItems: 1, maxItems: 20, items: { type: string, format: email } }
                role: { $ref: '#/components/schemas/Role' }
                seat: { $ref: '#/components/schemas/SeatId' }
                projectId: { type: string }
      responses:
        '201': { description: Sent, content: { application/json: { schema: { type: object, properties: { items: { type: array, items: { $ref: '#/components/schemas/Invitation' } }, skipped: { type: array, items: { type: object, properties: { email: { type: string }, reason: { type: string, enum: [already_member, already_invited, domain_blocked] } } } } } } } } }
        '402': { $ref: '#/components/responses/Quota' }
        '429': { $ref: '#/components/responses/RateLimited' }
  /invitations/{invitationId}:
    parameters: [{ name: invitationId, in: path, required: true, schema: { type: string } }]
    post:
      x-status: live
      tags: [Invitations]
      summary: Resend
      description: Email invites only (a link invite answers `400 invalid`; withdraw it and make another). A new code and a new expiry; the link in the earlier email stops working. It keeps its role and seat (withdraw it and invite again to change them). Counts toward the daily cap. Only someone who may invite with the invite's role and give its seat may resend it.
      x-permission: member.invite
      x-roles: [member (if allowed), admin, owner]
      responses: { '202': { description: Queued }, '404': { $ref: '#/components/responses/NotFound' }, '429': { $ref: '#/components/responses/RateLimited' } }
    delete:
      x-status: live
      tags: [Invitations]
      summary: Withdraw
      x-permission: member.manage
      x-roles: [admin, owner]
      responses: { '204': { description: Withdrawn }, '404': { $ref: '#/components/responses/NotFound' } }
  /invite-links:
    post:
      x-status: live
      tags: [Invitations]
      summary: Make an invite link for one person
      description: |
        An invite like an email one, for one person named by `note` (who it is for, up to 60 characters), with a `role`
        here and a `seat` for someone new to the organisation. Nothing is sent: the answer carries the `url` to pass on.
        It works once, for whoever opens it first and signs in (the invite rules' `allowedDomain` still applies), then
        stops; someone already in the workspace who opens it does not use it up. It lasts `days` (at most `invites.linkDays`, else `400 invalid`) and can be
        withdrawn before then (`DELETE /invitations/{invitationId}`). The same rules as inviting by email decide who may
        make one and with which role and seat, and it counts toward the daily cap.
      x-permission: member.invite
      x-roles: [member (if allowed), admin, owner]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required: [note, role, seat, days]
              properties:
                note: { type: string, minLength: 1, maxLength: 60 }
                days: { type: integer, minimum: 1 }
                role: { $ref: '#/components/schemas/Role' }
                seat: { $ref: '#/components/schemas/SeatId' }
                projectId: { type: string }
      responses:
        '201': { description: Made, content: { application/json: { schema: { $ref: '#/components/schemas/Invitation' } } } }
        '429': { $ref: '#/components/responses/RateLimited' }
  /invite-rules:
    get:
      x-status: live
      tags: [Invitations]
      summary: Who may invite, and the allowed email domain
      description: "Only callers allowed to invite read it. Until an admin changes it only admins and owners invite and any domain may join."
      x-permission: member.invite
      x-roles: [member (if allowed), admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/InviteRules' } } } } }
    patch:
      x-status: live
      tags: [Invitations]
      summary: Change who may invite, or the allowed email domain
      description: "`allowedDomain` must be the email domain of an admin or owner of the workspace (addresses are verified at sign-up); it applies to email and link invites alike."
      x-permission: member.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, minProperties: 1, properties: { adminsOnly: { type: boolean }, allowedDomain: { type: [string, 'null'] } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/InviteRules' } } } } }
  /access-requests:
    post:
      x-status: live
      tags: [Invitations]
      summary: Ask to join a workspace
      description: |
        A signed-in browser session only; an access key answers `403 session_required`.
        Asks a workspace's admins to let the caller in. `via` is what names the workspace, and only two things do:
        the code of an email invite sent to the caller's own address that has since expired (`invite`), or the
        token of a shared link that only the workspace's members may open (`share`). Anything else answers 404 with
        the same words, so codes and tokens cannot be probed. An invite that still works answers 409: use it.
        The request waits for an admin, who is told by email. Asking again while it waits answers the same and
        changes nothing. Limited per address like joining.
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/AccessRequestWrite' } } } }
      responses:
        '200': { description: Asked, content: { application/json: { schema: { type: object, required: [requested], properties: { requested: { type: boolean, enum: [true] } } } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
        '429': { $ref: '#/components/responses/RateLimited' }
    get:
      x-status: live
      tags: [Invitations]
      summary: People asking to join
      description: Oldest first, a page at a time. Anyone signed in who holds an expired invite or a members-only link can ask, so the list is paged.
      x-permission: member.manage
      x-roles: [admin, owner]
      parameters: [{ $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/cursor' }]
      responses:
        '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/AccessRequest' } } } }] } } } }
        '403': { $ref: '#/components/responses/Forbidden' }
  /access-requests/{requestId}:
    parameters: [{ name: requestId, in: path, required: true, schema: { type: string } }]
    delete:
      x-status: live
      tags: [Invitations]
      summary: Turn a request to join down
      x-permission: member.manage
      x-roles: [admin, owner]
      responses:
        '204': { description: Declined }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /access-requests/{requestId}/approve:
    parameters: [{ name: requestId, in: path, required: true, schema: { type: string } }]
    post:
      x-status: live
      tags: [Invitations]
      summary: Let someone who asked into the workspace
      x-permission: member.manage
      x-roles: [admin, owner]
      description: "The role follows the invite rule: an admin role needs an admin, an owner role an owner. `seat` is what they get if they hold none in the organisation yet (someone who does keeps theirs). There is no seat cap."
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [role, seat], properties: { role: { $ref: '#/components/schemas/Role' }, seat: { $ref: '#/components/schemas/SeatId' } } } } } }
      responses:
        '200': { description: Joined, content: { application/json: { schema: { type: object, properties: { userId: { type: string }, role: { $ref: '#/components/schemas/Role' } } } } } }
        '402': { $ref: '#/components/responses/Quota' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /join/preview:
    post:
      x-status: live
      tags: [Invitations]
      summary: Preview an invite before joining
      description: "Answers workspace name, role and the seat it gives someone new to the organisation only. Unknown, expired, withdrawn and switched-off codes all answer `{ workspaceName: '', role: member, seat: viewer, valid: false }`. The code travels in the body, never in the address, so it is not written to access logs. Limited per client address (`rateLimits.joinPerAddress` a window), on top of the general limit."
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/JoinRequest' } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { type: object, properties: { workspaceName: { type: string }, role: { $ref: '#/components/schemas/Role' }, seat: { $ref: '#/components/schemas/SeatId' }, valid: { type: boolean } } } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '429': { $ref: '#/components/responses/RateLimited' }
  /join:
    post:
      x-status: live
      tags: [Invitations]
      summary: Join with a link or email invite
      description: |
        A signed-in browser session only; an access key answers `403 session_required`. The code travels in the body.
        An email invite only works for the address it was sent to, and the workspace's allowed domain is checked
        against the verified email (`403 forbidden`). There is no seat cap: every paid seat is billed (ADR 0031).
        Someone already in keeps their role. Every code that does not work
        answers `404`. Limited per client address like the preview.
      x-permission: authenticated
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/JoinRequest' } } } }
      responses:
        '200': { description: Joined, content: { application/json: { schema: { $ref: '#/components/schemas/Me' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '402': { $ref: '#/components/responses/Quota' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/RateLimited' }
  # ───────────── Members
  /members:
    get:
      x-status: live
      tags: [Members]
      summary: People in the workspace
      description: "By name. Emails are only returned to admins and owners, and only they can find someone by email with `q`; others see name and avatar. Each member carries their `seat` in the organisation; `seats` counts everyone in this workspace by seat (not only this page). `role` and `seat` filter, each repeatable. There is no cap."
      x-permission: member.read
      x-roles: [member, admin, owner]
      parameters:
        - { name: q, in: query, schema: { type: string, maxLength: 80 } }
        - { name: role, in: query, schema: { type: array, items: { $ref: '#/components/schemas/Role' } }, style: form, explode: true }
        - { name: seat, in: query, schema: { type: array, items: { $ref: '#/components/schemas/SeatId' } }, style: form, explode: true }
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/Member' } }, seats: { $ref: '#/components/schemas/SeatCounts' } } }] } } } } }
  /members/{userId}:
    parameters: [{ $ref: '#/components/parameters/userId' }]
    patch:
      x-status: live
      tags: [Members]
      summary: Change someone's role
      description: Admins cannot set or change `owner`. The last owner cannot be demoted (`409`).
      x-permission: member.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [role], properties: { role: { $ref: '#/components/schemas/Role' } } } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { type: object, properties: { userId: { type: string }, role: { $ref: '#/components/schemas/Role' } } } } } }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
    delete:
      x-status: live
      tags: [Members]
      summary: Remove someone, or leave
      description: Their captures stay. Their access keys in this workspace are deleted in the same step, so they stop working at once. Admins cannot remove an owner; the last owner can neither leave nor be removed (`409`).
      x-permission: member.manage, or self to leave
      x-roles: [member, admin, owner]
      responses: { '204': { description: Removed }, '404': { $ref: '#/components/responses/NotFound' }, '409': { $ref: '#/components/responses/Conflict' } }
  /members/{userId}/seat:
    parameters: [{ $ref: '#/components/parameters/userId' }]
    patch:
      tags: [Members]
      summary: Change someone's seat
      x-changes: 'Pricing v2 (ADR 0031): Moving up charges the rest of the period at once, moving down takes effect at renewal (#443).'
      x-status: live
      description: |
        Sets the person's seat in the organisation, which holds in every workspace of it (ADR 0031 decision 4); they must be a
        member of this workspace (`404` otherwise). Admins and owners, signed in (an access key is refused). The bill
        follows the seats the organisation has; the organisation owner hears of every change by email (`seat_changed`), unless they
        made it.
      x-permission: member.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/SeatWrite' } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { userId: { type: string }, seat: { $ref: '#/components/schemas/SeatId' } } } } } }, '402': { $ref: '#/components/responses/Quota' }, '404': { $ref: '#/components/responses/NotFound' } }
  /members/{userId}/keys:
    parameters: [{ $ref: '#/components/parameters/userId' }]
    get:
      x-status: live
      tags: [Members]
      summary: Someone's access keys
      description: |
        One member's access keys in this workspace, newest first, expired ones included: the last four characters,
        scopes and expiry, never the key. Admins and owners can revoke anyone's key (`DELETE /tokens/{tokenId}`), and
        this is how they find which one. A user who is not a member here answers `404`. Rows of a key expired more
        than 30 days ago are deleted by a sweep.
      x-permission: member.manage
      x-roles: [admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { type: object, required: [items], properties: { items: { type: array, items: { $ref: '#/components/schemas/AccessKey' } } } } } } }
        '404': { $ref: '#/components/responses/NotFound' }

  # ───────────── Labels
  /labels:
    get:
      tags: [Labels]
      summary: Labels with use counts
      x-status: live
      x-permission: label.read
      x-roles: [member, admin, owner]
      description: |
        The popup shows selected labels plus `top=5` most used by the caller; the rest are found with `q`.
        A workspace that has never held a label is given six starter labels on its first read; once every label
        has been deleted the list stays empty.
        `group` is returned once a workspace sorts labels into groups (Area, Kind, Severity).
      parameters:
        - { name: q, in: query, schema: { type: string, maxLength: 40 } }
        - { name: top, in: query, description: Most used by the caller, schema: { type: integer, minimum: 1, maximum: 20 } }
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { items: { type: array, items: { $ref: '#/components/schemas/Label' } }, nextCursor: { type: [string, 'null'] } } } } } } }
    post:
      x-seat: 'organise'
      tags: [Labels]
      summary: New label (also "Create label" from the popup search)
      description: '`color` is optional; the server picks the next free colour. Members may create when the workspace allows it.'
      x-status: live
      x-permission: label.manage
      x-roles: [member (if allowed), admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/LabelWrite' } } } }
      responses: { '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/Label' } } } }, '409': { $ref: '#/components/responses/Conflict' } }
  /labels/{labelId}:
    parameters: [{ name: labelId, in: path, required: true, schema: { type: string } }]
    patch:
      x-seat: 'organise'
      tags: [Labels]
      summary: Rename, recolour, describe, reorder
      x-status: live
      x-permission: label.manage
      x-roles: [member (if allowed), admin, owner]
      requestBody: { content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/LabelWrite' }, { properties: { position: { type: integer, minimum: 0, description: 0-based; the others close up around it } } }] } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Label' } } } }, '404': { $ref: '#/components/responses/NotFound' }, '409': { $ref: '#/components/responses/Conflict' } }
    delete:
      x-seat: 'organise'
      tags: [Labels]
      summary: Delete a label nothing carries
      description: A label still on any capture answers `409 conflict`; take it off those captures first. A built-in label (`builtIn`) is never deleted and answers `403 forbidden`. Deleting never changes a capture.
      x-status: live
      x-permission: label.manage
      x-roles: [member (if allowed), admin, owner]
      responses: { '204': { description: Deleted }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' }, '409': { $ref: '#/components/responses/Conflict' } }

  # ───────────── Workspace settings
  /organisation:
    get:
      tags: [Workspace]
      summary: The organisation
      description: The organisation the workspace belongs to. It owns the plan, the billing, the trial and the storage pool (paid seats × the plan's gigabytes); its workspaces and seats are counted against the plan. Each person is counted once, however many of its workspaces they are in.
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Organisation' } } } } }
    patch:
      tags: [Workspace]
      summary: Rename the organisation, or hand it on
      description: The organisation owner only, whatever their role in this workspace; never an access key. `ownerId` hands the organisation to someone who is an owner or admin of one of its workspaces (otherwise `invalid`); they become the billing owner and the person handing it on keeps their roles. Of two hand-overs at once the second answers `conflict`. A rename and a hand-over go in separate requests; a body with both is `invalid`.
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/OrganisationPatch' } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Organisation' } } } }, '400': { $ref: '#/components/responses/Invalid' }, '403': { $ref: '#/components/responses/Forbidden' }, '409': { $ref: '#/components/responses/Conflict' } }
  /workspaces:
    post:
      tags: [Workspace settings]
      summary: New workspace
      description: Another workspace in the organisation of the one it is made from (the workspace menu's Add workspace), owned by the person making it. Admins and owners of that workspace only, signed in (an access key acts in its own workspace and is refused, 403). Past the plan's number of workspaces it answers 402 `quota` with the limit `workspaces`, its count and allowance, and the plan that allows more. Switch to it with the X-Workspace header and its id.
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [name], additionalProperties: false, properties: { name: { type: string, minLength: 2, maxLength: 60 } } } } } }
      responses: { '201': { description: Made, content: { application/json: { schema: { $ref: '#/components/schemas/Workspace' } } } }, '400': { $ref: '#/components/responses/Invalid' }, '402': { $ref: '#/components/responses/Quota' }, '403': { $ref: '#/components/responses/Forbidden' } }
  /workspace:
    get:
      tags: [Workspace settings]
      summary: General (name, web address)
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Workspace' } } } } }
    patch:
      tags: [Workspace settings]
      summary: Rename, change web address
      description: Send either field or both. A web address (`slug`) another workspace holds answers `conflict`.
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, minProperties: 1, properties: { name: { type: string, minLength: 2, maxLength: 60 }, slug: { type: string, pattern: '^[a-z0-9-]{3,40}$' } } } } } }
      responses: { '200': { description: The workspace now, content: { application/json: { schema: { $ref: '#/components/schemas/Workspace' } } } }, '400': { $ref: '#/components/responses/Invalid' }, '409': { $ref: '#/components/responses/Conflict' } }
    delete:
      tags: [Workspace settings]
      summary: Delete the workspace (Danger zone)
      description: >-
        Owner only. The JSON body's `confirm` must equal the workspace slug, else `invalid`; a request that carries
        `?confirm=` is refused as `invalid` whatever its body says. Every capture, comment, key, connection and
        membership is removed at once and nothing in the workspace can be opened again; its pictures and exports are
        removed from storage in the background.
      x-status: live
      x-permission: workspace.delete
      x-roles: [owner]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DeleteConfirmation' } } } }
      responses: { '202': { description: Deleted; storage is emptied in the background }, '400': { $ref: '#/components/responses/Invalid' } }
  /workspace/sharing:
    get:
      tags: [Workspace settings]
      summary: Sharing settings
      description: "Until an admin decides, links reach members only and pictures are withheld."
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/SharingSettings' } } } } }
    patch:
      tags: [Workspace settings]
      summary: Who can open shared links, and whether pictures are withheld
      description: "Send either field or both. `linkAudience` is the widest a link may be: narrowing it narrows the links already made, and they stay narrowed if it is widened again; a new link with no audience takes this setting."
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/SharingSettings' } } } }
      responses: { '200': { description: The settings now in force, content: { application/json: { schema: { $ref: '#/components/schemas/SharingSettings' } } } } }
  /workspace/data-policy:
    get:
      tags: [Workspace settings]
      summary: How long the workspace keeps its files
      description: >-
        `retentionDays` is the period the workspace chose; the retention sweep removes attachments past it, counted
        from each upload, whatever kind of item they belong to. No plan removes files (ADR 0031): until an admin
        chooses, `null`, files are kept.
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DataPolicy' } } } } }
    put:
      tags: [Workspace settings]
      summary: Choose how long files are kept
      description: >-
        The whole policy. Any period from 1 day to 100 years, or `null` to keep files, on any plan. The retention
        sweep removes attachments past the period chosen.
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/DataPolicy' } } } }
      responses:
        '200': { description: The policy now in force, content: { application/json: { schema: { $ref: '#/components/schemas/DataPolicy' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '402': { $ref: '#/components/responses/Quota' }
  /workspace/capture-privacy:
    get:
      tags: [Workspace settings]
      summary: What a capture may keep
      description: >-
        The capture kind's privacy setting. Both switches are enforced where the capture document is written, so a
        device with default settings still saves without an error: with `keepViewport` off, `POST /captures` and
        `POST /sync/push` save the capture without its viewport picture (and its thumb) and remove the upload made
        for it; with `keepDiagnostics` off they store no console and network (no `context.diagnostics`, no parts).
        Switching a part off stops new copies; what was stored while it was on stays until retention or deletion
        removes it.
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/CapturePrivacy' } } } } }
    patch:
      tags: [Workspace settings]
      summary: Turn a capture privacy switch on or off
      description: Send either switch, or both; only what is named changes.
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/CapturePrivacy' } } } }
      responses:
        '200': { description: The setting now in force, content: { application/json: { schema: { $ref: '#/components/schemas/CapturePrivacy' } } } }
        '400': { $ref: '#/components/responses/Invalid' }

  # ───────────── Plan and usage
  /usage:
    get:
      x-changes: 'Pricing v2 (ADR 0031): Answers MonthlyUsage: captures by person this month, the organisation''s storage; plan and seats leave (#429; weaves left in S1).'
      tags: [Plan and usage]
      summary: Plan, pictures stored and paid seats this month
      description: The calendar month in UTC. Allowances come from `config/plans.json`. Storage is pooled - each paid seat adds the plan's storage for a seat. `seats` counts the organisation's people by seat, each once; Viewer seats are free. There is no seat cap.
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Usage' } } } } }
  /usage/daily:
    get:
      tags: [Plan and usage]
      summary: Items by day (chart), loaded after the cards
      description: Every UTC day from `from` to `to`, both included (at most 366), days with none as 0. `projected` is this month's items at this month's pace, carried to its end.
      x-status: live
      x-permission: member.read
      x-roles: [member, admin, owner]
      parameters:
        - { name: from, in: query, required: true, schema: { type: string, format: date } }
        - { name: to, in: query, required: true, schema: { type: string, format: date } }
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { days: { type: array, items: { type: object, properties: { date: { type: string, format: date }, items: { type: integer } } } }, projected: { type: integer } } } } } }, '400': { $ref: '#/components/responses/Invalid' } }
  /entitlements:
    get:
      tags: [Plan and usage]
      summary: What the caller may do
      x-status: live
      description: |
        Every feature on or off, every limit with used and allowed, the plan, the caller's seat and the organisation's standing (ADR 0031 decision 12). `captures_per_month` counts the captures the caller made in the organisation this month, across its workspaces, deleted ones included; `capturesResetAt` is when it starts again.
        During a trial, features and the capture limit are the trial seat (Avid); seat stays the one the person holds, which the first bill charges for.
        Clients gate on this and nothing else; a refusal from any route says the same thing in QuotaRefusal.
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Entitlements' } } } } }
  /plans:
    get:
      tags: [Plan and usage]
      summary: Compare plans
      description: From `config/plans.json`, in the currencies a payment provider can charge. Prices come from here, never from page copy - each paid seat's price on each plan, per period, in minor units (yearly is the year's charge). Viewers are free.
      security: []
      x-status: live
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/PlanCatalogue' } } } } }
  /billing:
    get:
      x-changes: 'Pricing v2 (ADR 0031): Answers BillingSummary: plan, standing, period, currency, seats by kind, next charge, the saved card (#445).'
      tags: [Plan and usage]
      summary: Billing email and payment status
      description: "`status`: `none` never paid, `pending` checkout started, `active` paid up, `past_due` a renewal failed (the workspace is on Startup until a payment lands), `cancelled` ended. `seats` were counted when the subscription started."
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Billing' } } } }, '403': { $ref: '#/components/responses/Forbidden' } }
    patch:
      x-changes: 'Pricing v2 (ADR 0031): Takes BillingChange: email, plan or period; when each takes effect is ADR 0031 decision 17 (#441).'
      tags: [Plan and usage]
      summary: Change billing email
      description: Receipts go here, and Paystack knows the payer by it. One email pays for one workspace (`conflict` otherwise), and it is fixed while a subscription is active or past due (`conflict`).
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [email], properties: { email: { type: string, format: email } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Billing' } } } }, '409': { $ref: '#/components/responses/Conflict' } }
  /billing/checkout:
    get:
      tags: [Plan and usage]
      summary: What a move to Business would charge
      description: |
        Worked out by the same rule a checkout charges by, so a page never prices a move itself: every person in the
        organisation with a paid seat, each counted once (at least one), at the seat price for each interval, in minor
        units of `currency`. `available` is false when a checkout could not start now: payments not set up on this server,
        the provider's plans not matching `config/plans.json`, or the provider not answering.
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [plan, currency, seats, available, monthly, yearly]
                properties:
                  plan: { type: string, enum: [business] }
                  currency: { type: string }
                  seats: { type: integer }
                  available: { type: boolean }
                  monthly: { type: object, properties: { seatPrice: { type: integer }, total: { type: integer } } }
                  yearly: { type: object, properties: { seatPrice: { type: integer }, total: { type: integer } } }
        '403': { $ref: '#/components/responses/Forbidden' }
    post:
      x-changes: 'Pricing v2 (ADR 0031): Takes PlanCheckout: startup or business, period, currency. Charges the organisation''s seats as they are (#441).'
      tags: [Plan and usage]
      summary: Start a plan change (Move to Business)
      description: |
        Answers Paystack's hosted checkout for Business, every person in the organisation with a paid seat billed once as an
        Avid seat in US dollars (Viewer seats are free), billed to the billing email (the owner's own until one is set).
        Card details never touch this API. The price is `config/plans.json`'s: a Paystack plan that does not match it exactly answers 503
        rather than charge something else. The plan changes when Paystack reports the payment (`/billing/webhook`), not here.
        Startup is reached by cancelling (`/billing/manage`); Enterprise by talking to us.
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [plan, interval], properties: { plan: { type: string, enum: [business] }, interval: { type: string, enum: [monthly, yearly] } } } } } }
      responses: { '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/HostedLink' } } } }, '409': { $ref: '#/components/responses/Conflict' }, '503': { description: 'Payments are not answering, or not set up' } }
  /billing/manage:
    post:
      tags: [Plan and usage]
      summary: Manage the subscription (card, cancel)
      description: Answers Paystack's page where the owner changes the card or cancels. `conflict` when there is no subscription.
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      responses: { '201': { description: Created, content: { application/json: { schema: { $ref: '#/components/schemas/HostedLink' } } } }, '409': { $ref: '#/components/responses/Conflict' }, '503': { description: Payments are not answering } }
  /billing/receipts:
    get:
      tags: [Plan and usage]
      summary: Receipts
      description: Payments that landed, newest first. Paystack emails each receipt to the billing email; `reference` is Paystack's.
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      parameters: [{ $ref: '#/components/parameters/limit' }, { $ref: '#/components/parameters/cursor' }]
      responses: { '200': { description: OK, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/Receipt' } } } }] } } } } }
  /billing/webhook:
    post:
      tags: [Plan and usage]
      summary: Inbound Paystack webhook (payments and subscriptions)
      description: |
        Called by Paystack, not by people. Rejected with 401 unless `x-paystack-signature` is the HMAC SHA-512 of the raw body with the secret key.
        `charge.success`, `subscription.create`, `subscription.disable` and `invoice.payment_failed` update the workspace billed to the payer's email
        and its plan; each event applies once. Other events answer 200 and change nothing. A signed event that lacks what it needs answers 400.
      security: []
      x-status: live
      responses: { '200': { description: Accepted }, '400': { $ref: '#/components/responses/Invalid' }, '401': { $ref: '#/components/responses/Unauthenticated' }, '409': { description: The billing account kept changing while the event applied; Paystack delivers it again }, '503': { description: Billing is not set up on this server } }

  # ───────────── Integrations
  /integrations:
    get:
      tags: [Integrations]
      summary: What this workspace may install
      description: Bundled integrations and the workspace's own, its own first, each with whether and how it is installed here (ADR 0016).
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      parameters: [{ name: q, in: query, schema: { type: string, maxLength: 200 } }, { name: category, in: query, schema: { type: array, items: { type: string } } }, { name: installed, in: query, schema: { type: boolean } }, { name: ours, in: query, schema: { type: boolean } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/IntegrationCatalogue' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /integrations/{integrationId}:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: One integration, as the install screen reads it
      description: What it may do, on which hosts and where it shows, with the manifest hash an install must echo as its consent.
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/IntegrationListing' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /integrations/{integrationId}/icon:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: The integration's icon
      security: []
      x-status: live
      responses: { '200': { description: The icon, content: { image/svg+xml: {}, image/png: {} } }, '404': { $ref: '#/components/responses/NotFound' } }
  /integrations/{integrationId}/connection/callback:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: Where the tool sends the browser back after connecting (browser only)
      description: |
        One fixed address per integration (a GitHub App has a single Setup URL), so the installation travels in the
        signed `state` that `POST /installations/{installationId}/connection/authorize` made. Needs a browser session,
        signed in as the admin who started, in the same workspace; with nobody signed in it sends the browser to sign
        in and back. The state must be fresh (ten minutes) and the installation unchanged since, so it works once. The
        integration's `connection.confirm` checks what the tool returned, the connection is stored and the
        installation runs. Always answers with a redirect to the installation's page: `?connected=1`, or
        `?connect_error=<code>` with nothing stored.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      parameters: [{ name: state, in: query, required: true, schema: { type: string } }]
      responses: { '302': { description: 'To the installation''s page: ?connected=1, or ?connect_error=<code>' } }
  /integrations/requests:
    post:
      tags: [Integrations]
      summary: Ask for an app
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [name], properties: { name: { type: string, maxLength: 80 }, note: { type: string, maxLength: 500 } } } } } }
      responses: { '202': { description: Thanks } }
  /installations:
    get:
      tags: [Integrations]
      summary: Installed integrations, with each one's health
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      parameters: [{ name: state, in: query, schema: { type: string, enum: [setup, active, paused, failing] } }, { name: integrationId, in: query, schema: { type: string } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/InstallationPage' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
    post:
      tags: [Integrations]
      summary: Install with consent
      description: Needs a browser session. The consent echoes exactly what the version asks for; anything else answers 409 consent_mismatch.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/InstallWrite' } } } }
      responses: { '201': { description: Installed, content: { application/json: { schema: { $ref: '#/components/schemas/Installation' } } } }, '409': { description: 'Already installed, or consent_mismatch' }, '410': { description: No longer offered } }
  /installations/{installationId}:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: One installation
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Installation' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
    delete:
      tags: [Integrations]
      summary: Uninstall
      description: Needs a browser session. What it already wrote stays where it was written.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses: { '204': { description: Removed } }
  /installations/{installationId}/pause:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    post:
      tags: [Integrations]
      summary: Pause; its zones go empty and it leaves the Send menu
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Installation' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /installations/{installationId}/resume:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    post:
      tags: [Integrations]
      summary: Resume a paused installation
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Installation' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /installations/{installationId}/connection:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    put:
      tags: [Integrations]
      summary: Connect with a key
      description: |
        For an integration that connects with a key the workspace brings (an API key: OpenAI, Claude). The values are
        the connection's fields as the manifest names them. The integration checks the key with its tool first; only an
        accepted key is kept, sealed, and it is never answered back by any route. Needs a browser session.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [values], additionalProperties: false, properties: { values: { type: object, additionalProperties: { type: string, maxLength: 2000 } } } } } } }
      responses: { '200': { description: Connected, content: { application/json: { schema: { type: object, required: [account], properties: { account: { type: string } } } } } }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' }, '412': { $ref: '#/components/responses/Stale' }, '422': { $ref: '#/components/responses/Invalid' } }
    delete:
      tags: [Integrations]
      summary: Forget the key and disconnect
      description: The kept key is deleted and the installation waits to be connected again. Needs a browser session.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses: { '200': { description: Disconnected, content: { application/json: { schema: { type: object, required: [disconnected], properties: { disconnected: { type: boolean, enum: [true] } } } } } }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' }, '412': { $ref: '#/components/responses/Stale' } }
  /installations/{installationId}/lookups/{lookup}:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }, { name: lookup, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: A set-up field's choices, asked live
      description: |
        Runs the installation's `lookup` (an AI integration's `models`, a tool's repositories) as a call in its Log. 503
        when the tool does not answer: never an empty or stale list.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      parameters: [{ name: q, in: query, schema: { type: string, maxLength: 200 } }, { name: cursor, in: query, schema: { type: string } }]
      responses: { '200': { description: The choices, content: { application/json: { schema: { type: object, required: [items, nextCursor], properties: { items: { type: array, items: { type: object, required: [value, label], properties: { value: { type: string }, label: { type: string }, hint: { type: string } } } }, nextCursor: { type: [string, 'null'] } } } } } }, '404': { $ref: '#/components/responses/NotFound' }, '412': { description: Not connected yet }, '503': { description: The tool did not answer } }
  /installations/{installationId}/connection/authorize:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    post:
      tags: [Integrations]
      summary: Start connecting the installation to its tool
      description: |
        Answers the address to send the admin's browser to (an app install), carrying a signed `state` that binds the
        admin, the workspace, the installation and its revision for ten minutes. The tool sends the browser back to
        `GET /integrations/{integrationId}/connection/callback`. 503 while the integration's Live environment lacks a
        value or secret its manifest reads.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses: { '201': { description: Where to send the browser, content: { application/json: { schema: { type: object, required: [url], properties: { url: { type: string, format: uri } } } } } }, '400': { $ref: '#/components/responses/Invalid' }, '404': { $ref: '#/components/responses/NotFound' }, '503': { description: "The integration's Live environment lacks a value or secret its manifest reads; the message names who can fix it" } }
  /installations/{installationId}/consents:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: What was agreed
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ConsentList' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /installations/{installationId}/log:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: The Log, newest first
      description: Every call the installation made or answered, kept 30 days, with capture content replaced by ids and sizes.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      parameters: [{ name: sort, in: query, schema: { type: string, enum: [newest, oldest, slowest, fastest] } }, { name: failed, in: query, schema: { type: boolean } }, { name: direction, in: query, schema: { type: string, enum: [out, in] } }, { name: result, in: query, style: form, explode: true, schema: { type: array, items: { type: string } } }, { name: kind, in: query, style: form, explode: true, schema: { type: array, items: { type: string } } }, { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100 } }, { name: cursor, in: query, schema: { type: string } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/CallLog' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /installations/{installationId}/log/{callId}:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }, { name: callId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: One call, with every request it made
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/CallDetail' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /publisher/integrations:
    get:
      tags: [Integrations]
      summary: The integrations this workspace builds
      description: A session, or an access key with the `read` scope.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      parameters: [{ name: q, in: query, schema: { type: string, maxLength: 100 } }, { name: state, in: query, style: form, explode: true, schema: { type: array, items: { type: string } } }, { name: runtime, in: query, style: form, explode: true, schema: { type: array, items: { type: string, enum: [native, declarative, sandbox, remote] } } }, { name: sort, in: query, schema: { type: string, enum: [name, recent, oldest] } }, { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100 } }, { name: cursor, in: query, schema: { type: string } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/OwnedIntegrationPage' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /publisher/integrations/{integrationId}/versions/{version}/cases:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }, { name: version, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: A version's saved test cases (its fixtures)
      description: A session, or an access key with the `read` scope.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/TestCases' } } } }, '404': { $ref: '#/components/responses/NotFound' } }
  /publisher/integrations/{integrationId}/test-calls:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }]
    post:
      tags: [Integrations]
      summary: Run one call for the developer console
      description: |
        A session, or an access key with the `write` scope (a CLI, Postman, CI; see
        `docs/integrations/local-development.md`). Runs a stored version against this workspace's installation of the
        integration: the one `installationId` names, or without it the workspace's only one. With `caseId` a saved
        case's stubs answer for the tool and its expectation is compared. Without `caseId` the `input` runs for real
        against the Test environment: the runtime reaches the tool with Test's values and secrets, so a `send.file`
        files a real issue there. For a `remote` package the call goes to the Test environment's `endpoint` when it is
        set (a tunnel to your machine), else the manifest's endpoint; `target` in the answer says which. Effects are
        never applied: `apply` must be `false`. The answer and its Log entry carry every outbound request with its full
        address, headers and bodies (each up to 64 KB, `truncated` past it); a secret reads `•••• (<name>)` wherever
        it would show, also where the tool echoed it. Only console calls keep bodies; other calls keep their sizes.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      requestBody:
        content:
          application/json:
            schema: { $ref: '#/components/schemas/TestCallWrite' }
            examples:
              lookup:
                summary: A lookup, run for real against the Test environment
                value: { version: '0.1.0', call: lookup, input: { lookup: projects, query: '', cursor: null, values: {} }, apply: false }
              sendFile:
                summary: A send.file, answered by a saved case's stubs
                value:
                  version: '0.1.0'
                  call: send.file
                  apply: false
                  caseId: New issue on CAP-128
                  input:
                    target: { id: ACME, label: ACME }
                    report:
                      items: [{ itemId: c_128, kind: capture, title: Sale badge overlaps the price, note: On narrow screens the red badge sits on top of the price., attachments: [], capture: { tool: rect, page: { url: 'https://stride.shop/sale', title: Sale } } }]
                      project: { id: p_store, name: Storefront }
                      title: Sale badge overlaps the price
                      description: On narrow screens the red badge sits on top of the price.
                      labels: [{ name: ui, color: coral }]
                    markdown: On narrow screens the red badge sits on top of the price.
                    outcome: issue
                    change: null
                    values: { title: Sale badge overlaps the price, type: '10001', priority: High }
                    marker: f_01
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/TestRun' } } } }, '400': { $ref: '#/components/responses/Invalid' }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' } }
  /publisher/integrations/{integrationId}/requests:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: Ready-made test calls built from the saved cases
      description: |
        A session, or an access key with the `read` scope. One example per saved case of the stored version: its
        `body` is what to POST to `/publisher/integrations/{integrationId}/test-calls` as it stands (with `caseId`, so
        the case's stubs answer; drop `caseId` to reach the tool for real against the Test environment). No
        installation is named: the workspace's own is used.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/RequestExamples' } } } }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' } }
  /publisher/integrations/{integrationId}/environments:
    parameters: [{ name: integrationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Integrations]
      summary: The integration's Test and Live environments
      description: |
        For builders of the workspace that publishes the integration: its own, or for a bundled one the workspace the
        server names (BUNDLED_PUBLISHER_WORKSPACE). In each environment, every name the manifest reads and every name
        set in either environment, with its kind, whether the manifest uses it, and whether it is set. A value's text
        is answered; a secret's never, only when and by whom it was set. `missing` lists what the manifest reads and an
        environment has not got. Test is read by the developer console's calls to the real tool; Live by installations
        and connecting. 403 for a bundled integration no workspace publishes here (the operator's script sets those);
        404 for another publisher's. A session, or an access key with the `read` scope.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Environments' } } } }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' } }
  /publisher/integrations/{integrationId}/environments/{environment}/variables/{name}:
    parameters:
      - { name: integrationId, in: path, required: true, schema: { type: string } }
      - { name: environment, in: path, required: true, schema: { type: string, enum: [test, live] } }
      - { name: name, in: path, required: true, schema: { type: string, pattern: '^[a-z][a-z0-9_]{0,39}$' } }
    put:
      tags: [Integrations]
      summary: Set one value or secret of one environment
      description: |
        Needs a browser session. Creates the name when neither environment has it: `kind` is then required, unless the
        manifest reads the name, when the manifest's kind is used. A name keeps the kind it was created with in both
        environments (to change it, remove it from both and add it again), and never one the manifest contradicts.
        The value is trimmed; the key an app's tokens are signed with must be a private key in PEM form. For a
        `remote` package, `endpoint` is where the developer console's calls go instead of the manifest's endpoint
        (read from Test only; installations always use the manifest's): it must be a value, and an https address on
        port 443. Answers both environments.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/EnvVariableWrite' } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Environments' } } } }, '400': { $ref: '#/components/responses/Invalid' }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' }, '422': { description: "A name, kind or value the rules refuse (no kind for a new name, a kind that contradicts the stored one or the manifest, a key that is not one, a remote package's endpoint that is a secret or not https); the message says why", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } } }
    delete:
      tags: [Integrations]
      summary: Remove one value or secret from one environment
      description: Needs a browser session. Once a name is in neither environment its kind is forgotten. Answers both environments.
      x-status: live
      x-permission: integration.build
      x-seat: 'build_integrations'
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Environments' } } } }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' } }
  # ───────────── Access keys
  /tokens:
    get:
      tags: [Access keys]
      summary: My access keys
      description: Only the caller's own keys in this workspace, newest first, expired ones included until a sweep deletes rows expired more than 30 days ago. Shows the last four characters, never the key.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, required: [items], properties: { items: { type: array, items: { $ref: '#/components/schemas/AccessKey' } } } } } } } }
    post:
      x-seat: 'developer'
      tags: [Access keys]
      summary: New key (shown once)
      description: |
        Stored as a SHA-256 hash and its last four characters. `scopes` (default all three) can only narrow the caller's
        own role. `expiresAt` (ms) must be in the future; null or absent means no expiry. A signed-in browser session
        only: an access key answers `403 session_required`, so a key cannot mint a key that outlives it.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [name], properties: { name: { type: string, minLength: 1, maxLength: 60 }, scopes: { type: array, minItems: 1, items: { type: string, enum: [read, write, send] } }, expiresAt: { type: [integer, 'null'], maximum: 9007199254740991 } } } } } }
      responses:
        '201': { description: Created, content: { application/json: { schema: { allOf: [{ $ref: '#/components/schemas/AccessKey' }, { properties: { token: { type: string, description: Only in this answer } } }] } } } }
        '400': { description: 'An unknown or empty scope list, or an expiry that is not in the future' }
        '403': { description: "`session_required`: called with an access key" }
  /tokens/{tokenId}:
    parameters: [{ name: tokenId, in: path, required: true, schema: { type: string } }]
    delete:
      tags: [Access keys]
      summary: Revoke
      description: |
        Your own key (`self.write`), or anyone's key in the workspace when your role holds `member.manage` (admins and
        owners). Someone else's key answers 404 to anyone who cannot revoke it, as does a key of another workspace.
      x-status: live
      x-permission: self.write (own key) or member.manage (anyone's)
      x-roles: [member, admin, owner]
      responses: { '204': { description: Revoked }, '404': { description: No such key you may revoke } }

  # ───────────── Profile and preferences
  /me/profile:
    get:
      tags: [Profile and preferences]
      summary: Profile
      description: Before the caller saves one, the name the sign-in provider gave is offered, split at the first space, and `work` is null.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Profile' } } } } }
    patch:
      tags: [Profile and preferences]
      summary: Name and what you do
      description: |
        Only the fields that change. The saved first and last name become the name the workspace shows for you.
        Email, password and picture are changed with the sign-in provider, not here: sending them is `400`.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/ProfilePatch' } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Profile' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
  /me/profile/refresh:
    post:
      tags: [Profile and preferences]
      summary: Take my address and picture from the sign-in provider
      description: >-
        Called after the caller changed their primary address or picture with the sign-in provider. The server reads
        the provider's verified primary address and picture and writes them onto the caller; nothing is taken from the
        request, and the name is not touched. A signed-in browser session only (an access key answers
        `403 session_required`). `conflict` when another account here holds that address; `412` when the provider has
        no verified primary address for the caller.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      responses:
        '200': { description: The profile now, content: { application/json: { schema: { $ref: '#/components/schemas/Profile' } } } }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '403': { description: "`session_required`: called with an access key", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        '409': { $ref: '#/components/responses/Conflict' }
        '412': { description: "The sign-in provider has no verified primary address for the caller", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
        '503': { description: "The sign-in provider did not answer", content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
  /me/notifications:
    get:
      tags: [Profile and preferences]
      summary: Notification matrix and round-up
      description: |
        Per person and per workspace. Every event offered to the caller's role with each channel as chosen or its
        default. Workspace events (`member_joined`, `join_requested`, `seat_changed`, `connection_broken`) appear only for admins and owners.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Notifications' } } } } }
    patch:
      tags: [Profile and preferences]
      summary: Turn channels on or off per event
      description: |
        Only the channels and round-up fields that change; the rest keep their value. Workspace events (joins, plan
        limits, broken connections, seat changes) are only offered to admins and owners: naming one as a member is `403` and writes nothing.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { $ref: '#/components/schemas/NotificationsPatch' } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Notifications' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /dev/mail:
    get:
      tags: [Dev tools]
      summary: Every email the product sends (Mail lab)
      description: |
        Only on servers that turn dev tools on (`DEV_TOOLS=on`, development and staging, never production); elsewhere `404`.
        Each email's kind, its group and name, what it is about, whether people can turn it off, and how it reaches someone for real.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/MailLabList' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/mail/{kind}:
    get:
      tags: [Dev tools]
      summary: One email's sample as it would reach you (Mail lab)
      description: Subject, the inbox preview line, and the HTML and plain-text parts, addressed to you. `404` when dev tools are off or the kind is unknown.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      parameters: [{ name: kind, in: path, required: true, schema: { $ref: '#/components/schemas/MessageKind' } }]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/MailLabPreview' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/mail/{kind}/send:
    post:
      tags: [Dev tools]
      summary: Send one email's sample to yourself (Mail lab)
      description: Queues it to your own address only; the server's mailer sends it. `404` when dev tools are off or the kind is unknown.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      parameters: [{ name: kind, in: path, required: true, schema: { $ref: '#/components/schemas/MessageKind' } }]
      responses:
        '202': { description: Queued, content: { application/json: { schema: { $ref: '#/components/schemas/MailLabSent' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/states:
    get:
      tags: [Dev tools]
      summary: The states the workspace can be put in
      description: The organisation's standing (for its owner; null for anyone else) and every installation in the workspace that has a connection, with since when it is broken (null while it works). Admins and owners; `404` otherwise, and when dev tools are off.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevStates' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/states/trial-end:
    put:
      tags: [Dev tools]
      summary: Move the trial's end so a trial email is due, and send it
      description: 'Puts the organisation in its trial, nothing paid, ending three days from now (less a minute) or later today, and runs the trial emails'' sweep at once, so the owner gets the email that is due (Mailpit locally). The organisation owner only; `404` otherwise, and when dev tools are off. `400` for a plan agreed with us.'
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [endsIn], properties: { endsIn: { type: string, enum: [three_days, today] } } } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevStanding' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /dev/states/unpaid-notice:
    put:
      tags: [Dev tools]
      summary: Move the lapse so an unpaid notice is due, and send it
      description: 'Puts the organisation in read only from a day chosen so the unpaid notice asked for is due now: the one sent on lapsing (`daysLeft` null) or the one sent that many days before deletion (one of the catalogue''s days, 30, 7 and 1). One that ever paid lapses through a failed payment, one that never did through its trial ending. Then runs the unpaid notices'' sweep at once, so the owner gets the email (Mailpit locally). The organisation owner only; `404` otherwise, and when dev tools are off. `400` for a plan agreed with us, or days the catalogue sends no notice on.'
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [daysLeft], properties: { daysLeft: { type: [integer, 'null'], minimum: 1 } } } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevStanding' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /dev/states/storage:
    put:
      tags: [Dev tools]
      summary: Put the organisation's storage at 80% or full, and email the owner
      description: 'Reports the pool to the storage watch every upload reports to, first empty and then at 80% of the allowance (`nearly`) or at it (`full`), so the owner is told on every press. Nothing is uploaded or stored. The organisation owner only; `404` otherwise, and when dev tools are off. `400` when the organisation has no storage allowance.'
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [level], properties: { level: { type: string, enum: [nearly, full] } } } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevMailDue' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/states/key-expiring:
    post:
      tags: [Dev tools]
      summary: Make a key that expires in 3 days and send its expiry email
      description: 'Makes the caller an access key named "Expiring soon" that expires in 3 days, as making a key does (the seat must allow keys), marks it used now, and runs the hourly key check at once, so the caller gets the expiry email. `404` when dev tools are off; `403` when the seat cannot make keys.'
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevMailDue' } } } }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/states/roundup:
    post:
      tags: [Dev tools]
      summary: Send your weekly round-up now
      description: 'Queues the caller''s round-up for today, whatever the day, through the same email the weekly sweep sends: still once a day, and only when something reached their inbox in the last 7 days and the round-up is on. `404` when dev tools are off.'
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevMailDue' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/states/standing:
    put:
      tags: [Dev tools]
      summary: Put the organisation in a standing
      description: 'Writes the billing facts the standing is read from, as payments would leave them: trial (14 days from now, nothing paid), active (paid now), past due (a payment failed now), lapsed (a payment failed 7 days ago when it ever paid, otherwise the trial ended now). The organisation owner only; `404` otherwise, and when dev tools are off. `400` for a plan agreed with us, which is always active.'
      x-status: live
      x-permission: organisation owner
      x-roles: [organisation owner]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DevStandingChange' } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevStanding' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
        '409': { $ref: '#/components/responses/Conflict' }
  /dev/states/connections/{installationId}/break:
    post:
      tags: [Dev tools]
      summary: Break a connection through the real call path
      description: A stand-in tool answers one call as signed out; the call is logged, the connection is marked broken and the admins are emailed once, as for a real tool. `400` when the installation has no connection.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevConnectionChanged' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/states/connections/{installationId}/mend:
    post:
      tags: [Dev tools]
      summary: Mend a broken connection as a tool that accepts it again would
      description: A stand-in tool answers one call; the break ends as it would for a real tool. `400` when the installation has no connection.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevConnectionChanged' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }
  /dev/server:
    get:
      tags: [Dev tools]
      summary: What this server runs with
      description: The environment, address, sign-in, integration runtimes, storage and version. Never a secret. `404` when dev tools are off.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/DevServer' } } } }
        '404': { $ref: '#/components/responses/NotFound' }
  /me/extension:
    get:
      tags: [Profile and preferences]
      summary: Extension settings and installs I have signed in
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ExtensionSettings' } } } } }
    patch:
      tags: [Profile and preferences]
      summary: Dock, detail, default project, what to attach
      description: Cannot turn on anything the workspace's capture privacy has turned off (the viewport picture; diagnostics, which recording from page load gathers). The default project must be this workspace's.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ExtensionSettingsPatch' } } } }
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ExtensionSettings' } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '404': { $ref: '#/components/responses/NotFound' }

  # ───────────── Extension
  /config:
    get:
      tags: [Extension]
      summary: What a client needs before it can sign in
      description: Public. The API origin, the storage origin the extension asks host permission for, and the server version. Nothing about a workspace.
      security: []
      x-status: live
      responses: { '200': { description: OK } }
  /sync/pull:
    get:
      tags: [Extension]
      summary: Rows changed after a cursor
      description: Projects and captures past the cursor, ordered by updatedAt then id, tombstones included. The response's `cursor` is opaque; send it back as it is for the next page. Without one the whole workspace is read. A cursor this server did not write is refused with 400.
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      parameters:
        - { name: cursor, in: query, schema: { type: string, maxLength: 1000 } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 500, default: 200 } }
      responses: { '200': { description: OK } }
  /sync/push:
    post:
      x-changes: 'Pricing v2 (ADR 0031): A capture past the seat''s monthly allowance is refused with 402 quota (limit captures_per_month) (#425).'
      tags: [Extension]
      summary: Push projects and captures (last writer wins)
      description: At most 500 rows. Images never travel here, only asset ids. Losers come back in `superseded`. A project pushed under a name another live project has (names are unique per workspace, ignoring case and the spaces at the ends) is kept numbered, "Name (2)", and comes back in `superseded` for the device to take. A capture may carry its recording in `context.timeline` (`startedAt`, `durationMs`, at most 500 `events` as ConsoleEvent and 300 `network` as NetworkRequestDetail); the server moves it into the capture's console and network parts, drops credential headers, and never stores it in the capture document or returns it from pull. The workspace's capture policy is enforced before the merge; with `keepViewport` off a pushed viewport attachment (and its thumb) is dropped unless the server already holds it, and with `keepDiagnostics` off no diagnostics or recording is stored.
      x-status: live
      x-permission: item.write
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK }, '413': { $ref: '#/components/responses/Limit' } }
  /assets/upload:
    post:
      tags: [Extension]
      summary: Ask for a signed upload slot (10 minutes)
      description: Content type is checked against the role; size against per-kind limits and the plan's storage. A `viewport` slot is granted even while capture privacy has `keepViewport` off; the policy is enforced when the capture document is saved, and the upload made for a dropped picture is removed then.
      x-status: live
      x-permission: asset.write
      x-roles: [member, admin, owner]
      responses: { '201': { description: Slot }, '402': { $ref: '#/components/responses/Quota' }, '410': { description: "The attachment was removed by the plan's retention and is not uploaded again, the item was deleted, or the workspace is gone." } }
  /assets/{assetId}:
    parameters: [{ name: assetId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Extension]
      summary: Short-lived read URL for one asset
      x-status: live
      x-permission: asset.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK }, '404': { $ref: '#/components/responses/NotFound' } }
  /me/extension/sign-ins:
    get:
      tags: [Extension]
      summary: Where the extension is signed in as me
      description: |
        Every browser the extension is signed in from as the caller, in any workspace they are in, newest first: the key
        each sign-in made, named after the browser. A signed-in browser only; an access key is refused.
      x-status: live
      x-permission: self.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/ExtensionSignInList' } } } }, '403': { $ref: '#/components/responses/Forbidden' } }
  /me/extension/sign-ins/{id}:
    parameters: [{ name: id, in: path, required: true, schema: { type: string } }]
    delete:
      tags: [Extension]
      summary: Sign the extension out of one browser
      description: Deletes the key that browser's sign-in made, so the extension there is signed out on its next call. A signed-in browser only.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      responses: { '204': { description: Signed out }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' } }
  /me/extension/heartbeat:
    post:
      tags: [Extension]
      summary: The extension says it is installed (ticks the setup step)
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [browser, version], properties: { browser: { type: string, minLength: 1, maxLength: 80 }, version: { type: string, minLength: 1, maxLength: 40 } } } } } }
      responses: { '204': { description: OK }, '400': { $ref: '#/components/responses/Invalid' } }
  /me/errors:
    post:
      tags: [System]
      summary: The extension or the dashboard reports one failure (ADR 0019)
      description: |
        Handed to where failures are collected, with the caller's workspace and user ids. A report never holds the
        address, the title or the content of the page it happened on: the client replaces anything that looks
        like a web address in the message and the stack before sending. Unknown fields are refused.
      x-status: live
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [source, name, message, build, browser, at]
              properties:
                source: { type: string, enum: [worker, board, page, popup, onboarding, dashboard] }
                name: { type: string, minLength: 1, maxLength: 80 }
                message: { type: string, minLength: 1, maxLength: 500 }
                stack: { type: string, maxLength: 8000 }
                build: { type: string, minLength: 1, maxLength: 80 }
                browser: { type: string, minLength: 1, maxLength: 80 }
                doing: { type: string, maxLength: 60, pattern: '^[A-Za-z0-9_.:-]+$' }
                at: { type: integer, minimum: 0 }
      responses: { '204': { description: OK }, '400': { $ref: '#/components/responses/Invalid' } }

  # ───────────── Extension: sign-in, send sheets, filings
  /auth/sign-in-events:
    post:
      tags: [System]
      summary: Inbound sign-in provider webhook (a user changed or was deleted there)
      description: |
        Called by the sign-in provider (Clerk), not by people. Rejected with 401 unless the delivery carries Clerk's
        signature (`svix-id`, `svix-timestamp`, `svix-signature`) made with this endpoint's signing secret; a delivery
        whose signed time is more than a few minutes off is refused too. Only whose news it is comes from the event:
        on `user.updated` the account bound to that sign-in takes the provider's verified primary address and picture,
        read from the provider (the name is ours and stays); two accounts that exchanged addresses are written together.
        On `user.deleted` no data is deleted here. An account still present less than two minutes after the deletion
        answers 503 (our own delete may be finishing), so it is delivered again; one still present after that has its
        access keys and extension sign-in grants removed and is reported for an operator. Other events answer 200 and
        change nothing. A delivery arriving twice ends in the same place.
      security: []
      x-status: live
      responses:
        '200': { description: 'Accepted; `applied` says whether anything changed', content: { application/json: { schema: { type: object, required: [applied], properties: { applied: { type: boolean } } } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '401': { $ref: '#/components/responses/Unauthenticated' }
        '409': { description: 'The address the provider holds for this user belongs to another account here; reported, and the provider delivers it again' }
        '503': { description: 'The provider could not be read just now, the deleted account is still here and may be on its way out, or this server has no signing secret (development only)' }
  /auth/extension/start:
    post:
      tags: [Extension]
      x-status: live
      summary: Start extension sign-in (Sign in button)
      description: |
        Device-style flow so no key is pasted. Answers a `deviceCode` (kept by the extension) and a `verifyUrl` the
        extension opens in a tab. The person signs in there and approves; the extension polls `/auth/extension/token`.
        Codes live 10 minutes and are single use. `verifyUrl` is always on our own domain.
      security: []
      requestBody: { content: { application/json: { schema: { type: object, properties: { extensionVersion: { type: string }, browser: { type: string } } } } } }
      responses: { '201': { description: Started, content: { application/json: { schema: { type: object, properties: { deviceCode: { type: string }, userCode: { type: string }, verifyUrl: { type: string, format: uri }, interval: { type: integer }, expiresAt: { type: integer, description: 'On the server''s clock.' }, expiresIn: { type: integer, description: 'Seconds the code lives from this answer; set a local deadline from it.' } } } } } } }
  /auth/extension/request:
    get:
      tags: [Extension]
      x-status: live
      summary: What is asking to sign in with a code (dashboard session only)
      description: |
        Read by the approval page before the person approves, so they can tell the request is theirs: the browser and
        extension version the start request sent, and when the code was made. `code` is the `userCode` (case and
        separators are ignored). Only a code still waiting answers; an unknown, expired, approved or used code answers
        404, so the answer never tells whether a code existed.
      security: [{ session: [] }]
      x-permission: self.write
      x-roles: [member, admin, owner]
      parameters: [{ name: code, in: query, required: true, schema: { type: string, minLength: 4, maxLength: 20 } }]
      responses:
        '200': { description: Waiting, content: { application/json: { schema: { type: object, required: [userCode, browser, extensionVersion, createdAt, expiresAt], properties: { userCode: { type: string }, browser: { type: string }, extensionVersion: { type: string, description: 'Empty when the extension did not send one.' }, createdAt: { type: integer, description: 'On the server''s clock.' }, expiresAt: { type: integer, description: 'On the server''s clock.' } } } } } }
        '400': { $ref: '#/components/responses/Invalid' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '404': { $ref: '#/components/responses/NotFound' }
        '429': { $ref: '#/components/responses/RateLimited' }
  /auth/extension/approve:
    post:
      tags: [Extension]
      x-status: live
      summary: Approve a sign-in from the browser tab (dashboard session only)
      description: |
        Shows the `userCode` to compare (case and separators are ignored). The key collected by the extension is named
        after the browser and acts as the caller in `workspaceId` (default: the current one). An unknown, expired or
        already approved code, or a workspace the caller is not in, answers 404. An access key (`1w_…`) answers 403
        `session_required`: only a signed-in browser session can approve, so a key cannot mint more keys.
      security: [{ session: [] }]
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, required: [userCode], properties: { userCode: { type: string }, workspaceId: { type: string } } } } } }
      responses: { '204': { description: Approved }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' } }
  /auth/extension/token:
    post:
      tags: [Extension]
      x-status: live
      summary: Poll for the key
      description: Answers `pending` (428) until approved, then the key once. Polling faster than `interval` answers 429.
      security: []
      requestBody: { content: { application/json: { schema: { type: object, required: [deviceCode], properties: { deviceCode: { type: string } } } } } }
      responses:
        '200': { description: Approved, content: { application/json: { schema: { type: object, properties: { token: { type: string }, me: { $ref: '#/components/schemas/Me' } } } } } }
        '428': { description: Not approved yet }
        '429': { $ref: '#/components/responses/RateLimited' }
        '410': { description: Expired or already used }
  /me/extension/site-defaults:
    get:
      tags: [Profile and preferences]
      x-status: live
      summary: Per-site defaults (project, installation and place for stride.shop)
      x-permission: self.read
      x-roles: [member, admin, owner]
      parameters: [{ name: site, in: query, schema: { type: string } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { items: { type: array, items: { $ref: '#/components/schemas/SiteDefault' } } } } } } } }
  /me/extension/site-defaults/{site}:
    parameters: [{ name: site, in: path, required: true, schema: { type: string } }]
    put:
      tags: [Profile and preferences]
      x-status: live
      summary: Set the default project, installation and place for a site
      description: Enables "Save and send" in the popup. The installation must be one this workspace can send through, so this answers 503 without an integration runtime.
      x-permission: self.write
      x-roles: [member, admin, owner]
      requestBody: { content: { application/json: { schema: { type: object, properties: { projectId: { type: [string, 'null'], minLength: 1, maxLength: 100 }, installationId: { type: [string, 'null'], minLength: 1, maxLength: 64 }, action: { type: [string, 'null'], minLength: 1, maxLength: 40 }, target: { type: [string, 'null'], minLength: 1, maxLength: 512 } } } } } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/SiteDefault' } } } }, '400': { $ref: '#/components/responses/Invalid' }, '404': { $ref: '#/components/responses/NotFound' } }
    delete:
      tags: [Profile and preferences]
      x-status: live
      summary: Forget the site default
      x-permission: self.write
      x-roles: [member, admin, owner]
      responses: { '204': { description: Removed }, '404': { $ref: '#/components/responses/NotFound' } }
  /ai:
    get:
      tags: [Integrations]
      summary: AI features, their models and usage
      description: |
        Settings → AI features. Each AI feature (a zone an AI integration implements; today `extension.text`, suggesting words in
        Live text): whether it is on, what answers it (the installation an admin picked, else the one connected first),
        every connected AI integration that could, and what it used since the first of the month (UTC), counted from the
        ledger of answered requests.
      x-status: live
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, required: [features, since], properties: { features: { type: array, items: { type: object, required: [zone, enabled, answeredBy, picked, offered, usage, perPerson], properties: { zone: { type: string, enum: [extension.text] }, enabled: { type: boolean }, answeredBy: { oneOf: [{ type: object, required: [installationId, integrationId, name, model], properties: { installationId: { type: string }, integrationId: { type: string }, name: { type: string }, model: { type: [string, 'null'] } } }, { type: 'null' }] }, picked: { type: boolean }, offered: { type: array, items: { type: object, required: [installationId, integrationId, name, model], properties: { installationId: { type: string }, integrationId: { type: string }, name: { type: string }, model: { type: [string, 'null'] } } } }, usage: { type: object, required: [requests, input, output], properties: { requests: { type: integer }, input: { type: integer }, output: { type: integer } } }, perPerson: { type: integer } } } }, since: { type: number } } } } } }, '403': { $ref: '#/components/responses/Forbidden' } }
  /ai/features/{zone}:
    parameters: [{ name: zone, in: path, required: true, schema: { type: string, enum: [extension.text] } }]
    put:
      tags: [Integrations]
      summary: Turn an AI feature on or off and pick its model
      description: |
        `installationId` must be a connected AI integration that implements the feature (null: the one connected first);
        `model`, when given, becomes that installation's model. Needs a browser session.
      x-status: live
      x-permission: connection.manage
      x-roles: [admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [enabled, installationId], additionalProperties: false, properties: { enabled: { type: boolean }, installationId: { type: [string, 'null'] }, model: { type: string, maxLength: 120 } } } } } }
      responses: { '200': { description: The feature as it is now, content: { application/json: { schema: { type: object, required: [zone, enabled, answeredBy, picked, offered, usage, perPerson], properties: { zone: { type: string, enum: [extension.text] }, enabled: { type: boolean }, answeredBy: { oneOf: [{ type: object, required: [installationId, integrationId, name, model], properties: { installationId: { type: string }, integrationId: { type: string }, name: { type: string }, model: { type: [string, 'null'] } } }, { type: 'null' }] }, picked: { type: boolean }, offered: { type: array, items: { type: object, required: [installationId, integrationId, name, model], properties: { installationId: { type: string }, integrationId: { type: string }, name: { type: string }, model: { type: [string, 'null'] } } } }, usage: { type: object, required: [requests, input, output], properties: { requests: { type: integer }, input: { type: integer }, output: { type: integer } } }, perPerson: { type: integer } } } } } }, '403': { $ref: '#/components/responses/Forbidden' }, '404': { $ref: '#/components/responses/NotFound' }, '412': { $ref: '#/components/responses/Stale' }, '422': { $ref: '#/components/responses/Invalid' } }
  /text-suggestions/model:
    get:
      tags: [Integrations]
      summary: The AI Live text would ask
      description: The connected AI integration (OpenAI or Claude) that answers Live text's AI button, or null. The extension shows the button only with one; with several, the one connected first.
      x-status: live
      x-permission: item.write
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, required: [model], properties: { model: { oneOf: [{ type: object, required: [installationId, integrationId, name], properties: { installationId: { type: string }, integrationId: { type: string }, name: { type: string } } }, { type: 'null' }] } } } } } }, '403': { $ref: '#/components/responses/Forbidden' } }
  /text-suggestions:
    post:
      tags: [Integrations]
      summary: New words for the ones picked in Live text
      description: |
        Sends only the picked words, the rest of that element's words (at most 5,000 characters) and the request to the
        workspace's connected AI integration, with the guardrails in `config/ai/text-suggest.md` as its instructions. A
        request that is not a text edit is refused before any model is called (422); the answer is checked again and
        refused when it is code, markup or far longer than the words it replaces. Each person has 10 a minute (429).
        The call and the tokens it used are in that integration's Log.
      x-status: live
      x-permission: item.write
      x-roles: [member, admin, owner]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [selected, context, prompt], additionalProperties: false, properties: { selected: { type: string, minLength: 1, maxLength: 2000 }, context: { type: string, maxLength: 5000 }, prompt: { type: string, minLength: 1, maxLength: 500 } } } } } }
      responses: { '200': { description: The new words, content: { application/json: { schema: { type: object, required: [text, model], properties: { text: { type: string }, model: { type: object, required: [installationId, integrationId, name], properties: { installationId: { type: string }, integrationId: { type: string }, name: { type: string } } } } } } } }, '412': { description: No AI integration is connected }, '422': { $ref: '#/components/responses/Invalid' }, '429': { $ref: '#/components/responses/RateLimited' }, '503': { description: The AI did not answer or its answer could not be used } }
  /send-options:
    get:
      tags: [Extension]
      x-status: live
      summary: The Send menu for one capture's project
      description: |
        Every installation whose integration contributes a Send to entry, is ready (not in set-up or paused) and reaches
        the project, one row per declared outcome grouped by what it does (`create`, `add_to`), the caller's last used
        first. Empty `items` with `connectUrl` draws "Nothing to send to yet". Viewers get `canSend: false`. Without an
        integration runtime on the server this answers 503.
      x-permission: item.read
      x-roles: [member, admin, owner]
      parameters: [{ name: projectId, in: query, required: true, schema: { type: string } }]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/SendOptions' } } } } }
  /installations/{installationId}/send-form:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Extension]
      x-status: live
      summary: The send sheet for one installation's outcome
      description: |
        The entry's `fields` for the action (those whose `when` names it, or has none), with `values` prefilled from
        the capture (`from`), then the caller's last choice through this installation, then each field's default.
        `target` is the place: the one asked for, the caller's last, or the project's own. `change` is the host's own
        field for an outcome that needs an open change; with `url`, the change a preview address belongs to is found
        through the entry's `changes` lookup. The server only reads the manifest; it never branches on the integration.
        That lookup counts against the caller's and the installation's live lookups a minute (`429` past them).
      x-permission: item.send
      x-roles: [member, admin, owner]
      parameters:
        - { name: action, in: query, required: true, schema: { type: string, examples: [issue, comment] } }
        - { name: itemId, in: query, required: true, schema: { type: string } }
        - { name: target, in: query, description: Re-ask after the place changes, schema: { type: string } }
        - { name: url, in: query, description: 'The captured page, to find the open change a preview belongs to', schema: { type: string } }
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/SendForm' } } } }, '404': { $ref: '#/components/responses/NotFound' }, '429': { $ref: '#/components/responses/RateLimited' }, '503': { description: The tool could not answer the changes lookup } }
  /installations/{installationId}/send-form/options/{field}:
    parameters: [{ name: installationId, in: path, required: true, schema: { type: string } }, { name: field, in: path, required: true, schema: { type: string, examples: [target, change, assignee] } }]
    get:
      tags: [Extension]
      x-status: live
      summary: Search one send field's choices
      description: |
        `target` asks the entry's `targets` lookup, `change` its `changes` lookup (scoped to `target`), and a choice
        field its own lookup, scoped to `target` when it depends on it. Each call is kept in the installation's Log. A
        field with no lookup answers 404; a tool that cannot answer answers 503, and the Log keeps its reason. Each person, and each
        installation across everyone, has a few lookups a minute (`config/plans.json`); past that it answers 429 and
        nothing reaches the tool.
      x-permission: item.send
      x-roles: [member, admin, owner]
      parameters:
        - { name: target, in: query, description: Required for a field that depends on the place, schema: { type: string } }
        - { name: q, in: query, schema: { type: string } }
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/cursor'
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { items: { type: array, items: { type: object, properties: { value: { type: string }, label: { type: string }, hint: { type: string } } } }, nextCursor: { type: [string, 'null'] } } } } } }, '404': { $ref: '#/components/responses/NotFound' }, '429': { $ref: '#/components/responses/RateLimited' }, '503': { description: The tool could not answer } }
  /filings:
    post:
      x-seat: 'bulk_send (more than one capture) and agents (to open work)'
      tags: [Extension]
      x-status: live
      summary: Send one or more captures, as one item, with the sheet's values
      description: |
        Answers at once with a filing in `queued`; uploads and the installation's `send.file` call carry on in the
        background, so the sheet can close. `itemIds` (1–20, unique, all in one project the installation reaches) are
        sent together and land in the tool as ONE item: the title and description come from the sheet, then each
        capture's pictures and note follow in the order given. Values are re-validated against the entry's fields for
        the action on the server: unknown keys, missing required fields and wrong kinds answer 400. `target` picks
        where it lands (default: the project's place); `change` is the open change a comment goes on. A failure keeps
        the tool's reason in `error.reason`. Idempotent per `Idempotency-Key`. Deleting any member capture deletes the
        whole filing. Without an integration runtime on the server this answers 503.
      x-permission: item.send
      x-roles: [member, admin, owner]
      parameters: [{ name: Idempotency-Key, in: header, required: true, schema: { type: string } }]
      requestBody: { content: { application/json: { schema: { type: object, additionalProperties: false, required: [itemIds, installationId, action, values], properties: { itemIds: { type: array, minItems: 1, maxItems: 20, items: { type: string } }, installationId: { type: string, maxLength: 64 }, action: { type: string, maxLength: 40 }, target: { type: string, maxLength: 512 }, change: { type: string, maxLength: 60 }, values: { type: object, additionalProperties: { oneOf: [{ type: string }, { type: boolean }, { type: array, items: { type: string } }] } }, remember: { type: boolean, default: true } } } } } }
      responses: { '202': { description: Accepted, content: { application/json: { schema: { $ref: '#/components/schemas/Filing' } } } }, '402': { $ref: '#/components/responses/Quota' } }
  /filings/{filingId}:
    parameters: [{ name: filingId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Extension]
      x-status: live
      summary: Progress, result or the tool's reason
      description: Poll every 2 s while `queued` or `uploading` or `sending`, or listen on `/events`.
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Filing' } } } } }
  /filings/{filingId}/retry:
    parameters: [{ name: filingId, in: path, required: true, schema: { type: string } }]
    post:
      x-seat: 'bulk_send (more than one capture) and agents (to open work)'
      tags: [Extension]
      x-status: live
      summary: Try again after a failure
      x-permission: item.send
      x-roles: [member, admin, owner]
      responses: { '202': { description: Requeued, content: { application/json: { schema: { $ref: '#/components/schemas/Filing' } } } }, '409': { $ref: '#/components/responses/Conflict' } }
  /items/{itemId}/filings:
    parameters: [{ $ref: '#/components/parameters/itemId' }]
    get:
      tags: [Item parts]
      x-status: live
      summary: Where this capture was sent, with live status (the pill)
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { items: { type: array, items: { $ref: '#/components/schemas/Filing' } } } } } } } }
  /events:
    get:
      tags: [Extension]
      x-status: live
      summary: Live change ticks for the dashboard and side panel (SSE)
      description: |
        `text/event-stream` of thin ticks, each `event: change` with `data: {"kind","at"}` and never a payload:
        `kind` is one of `items`, `inbox`, `filings`, `labels`, `members`, `billing`, `integrations` (an installation made,
        removed, paused, resumed or connected, or a project's place changed), and `at` is when it happened (epoch ms).
        React by refetching the reads you already use (sync pull, list routes, inbox counts); a tick says only that
        something of that kind changed in your workspace. Scoped to the caller's workspace; an access key needs the
        `read` scope. A comment line every 25 s keeps proxies open, and the server ends every stream after ten-odd
        minutes: reconnect and carry on (the reconnect re-checks the token, so revoked keys and removed members stop
        hearing the workspace within that bound). There is no `Last-Event-ID` resume: ticks carry no history, so
        reconnect and refetch, which your polling does anyway — a dropped stream is never worse than polling alone.
        Opening the stream is charged as one request; the ticks consume no per-request budget. At most
        `rateLimits.streamsPerWorkspace` streams per workspace and server process; past that the stream answers `429`.
      x-permission: item.read
      x-roles: [member, admin, owner]
      responses:
        '200': { description: Stream of change ticks, content: { text/event-stream: { schema: { type: string } } } }
        '429': { description: Too many open streams for this workspace }
  /workspace/exports:
    post:
      tags: [Workspace settings]
      summary: Export the workspace (Privacy)
      description: >-
        A zip of every capture document (with its console and network) and every picture, clip and voice note, built in
        the background. One export runs at a time per workspace; another answers `conflict`. The download link goes only
        to the person who started it, from `GET /workspace/exports/{exportId}`, and lives 24 h. When the export is
        ready they are emailed a link to the dashboard's export page, which asks for a sign-in and answers the download
        through this same route (never the signed link itself); a build that fails emails them that instead.
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      responses: { '202': { description: Started, content: { application/json: { schema: { type: object, properties: { id: { type: string } } } } } }, '409': { $ref: '#/components/responses/Conflict' } }
  /workspace/exports/{exportId}:
    parameters: [{ name: exportId, in: path, required: true, schema: { type: string } }]
    get:
      tags: [Workspace settings]
      summary: Export status and download link
      description: Only for the person who started the export; anyone else gets `404`. After 24 h the zip is removed and this answers `gone`.
      x-status: live
      x-permission: workspace.manage
      x-roles: [admin, owner]
      responses: { '200': { description: OK, content: { application/json: { schema: { type: object, properties: { state: { type: string, enum: [running, ready, failed] }, url: { type: [string, 'null'] }, expiresAt: { type: [integer, 'null'] } } } } } }, '404': { $ref: '#/components/responses/NotFound' }, '410': { $ref: '#/components/responses/Gone' } }

components:
  securitySchemes:
    session:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Clerk session JWT, used by the dashboard. Verified on every request (60 s cache).
    accessKey:
      type: http
      scheme: bearer
      description: Personal access key `1w_…`, made under Settings → API and agents. Looked up by hash; acts as its maker.
  parameters:
    limit: { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
    limitLong: { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 500, default: 200 } }
    cursor: { name: cursor, in: query, schema: { type: string } }
    ifMatch: { name: If-Match, in: header, schema: { type: string }, description: The record's etag; a stale one answers 412 }
    idempotencyKey: { name: Idempotency-Key, in: header, schema: { type: string, maxLength: 200 }, description: Replays the first answer for a repeat with the same body }
    workspace: { name: X-Workspace, in: header, schema: { type: string } }
    itemId: { name: itemId, in: path, required: true, schema: { type: string }, description: Id or ref such as CAP-128 }
    captureId: { name: captureId, in: path, required: true, schema: { type: string }, description: The id or ref of an item of kind capture }
    projectId: { name: projectId, in: path, required: true, schema: { type: string } }
    userId: { name: userId, in: path, required: true, schema: { type: string } }
    inboxItemId: { name: inboxItemId, in: path, required: true, schema: { type: string }, description: An inbox entry's own id }
  responses:
    Unauthenticated: { description: No or bad token, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Forbidden: { description: Role lacks the permission, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    NotFound: { description: Not in this workspace, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Conflict: { description: Conflicts with current state, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Stale: { description: If-Match did not match, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Invalid: { description: Failed validation, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Quota: { description: 'Over a plan limit (code quota, details QuotaRefusal), or the organisation is lapsed and read only (code lapsed, details LapsedRefusal)', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Limit: { description: Too large, content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Gone: { description: 'Expired or used up (an invite, a share link)', content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    Pending: { description: Still in progress (the same Idempotency-Key is running), content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } } }
    RateLimited:
      description: Over the rate limit
      headers: { Retry-After: { schema: { type: integer }, description: Seconds to wait } }
      content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } }
  schemas:
    IntegrationCatalogue: { type: object, description: 'A page of IntegrationCard with total and counts (contracts integration/http/marketplace.ts).' }
    IntegrationListing: { type: object, description: 'Listing (contracts integration/http/marketplace.ts).' }
    InstallationPage: { type: object, description: 'A page of InstallationSummary.' }
    InstallWrite: { type: object, description: 'InstallWrite (contracts integration/http/installations.ts).' }
    Installation: { type: object, description: 'Installation (contracts integration/http/installations.ts).' }
    ConsentList: { type: object, description: '{ items: Consent[] }.' }
    CallLog: { type: object, description: 'A page of CallSummary with total and counts (contracts integration/http/log.ts).' }
    CallDetail:
      type: object
      description: CallDetail (contracts integration/http/log.ts) with its summary, request, response, validation and effects.
      properties:
        http: { type: array, items: { $ref: '#/components/schemas/OutboundRequest' } }
        target: { type: [string, 'null'], description: "Where a remote package's call went: the manifest's endpoint, or for a console call the Test environment's endpoint when set. Null for other runtimes." }
    OutboundRequest:
      type: object
      description: "One request a call made. Secrets read `•••• (<name>)`. Bodies are kept in full (up to 64 KB) for console calls only; other calls keep `{ text: '<n> bytes', truncated: true }`."
      required: [method, url, host, path, status, statusText, durationMs, blocked, requestHeaders, requestBody, responseHeaders, responseBody]
      properties:
        method: { type: string }
        url: { type: string, description: 'The full address, query included.' }
        host: { type: string }
        path: { type: string }
        status: { type: [integer, 'null'] }
        statusText: { type: [string, 'null'] }
        durationMs: { type: integer, minimum: 0 }
        blocked: { type: boolean, description: 'Refused before it left: no status and no reply.' }
        requestHeaders: { type: object, additionalProperties: { type: string } }
        requestBody: { oneOf: [{ $ref: '#/components/schemas/HttpBody' }, { type: 'null' }] }
        responseHeaders: { type: object, additionalProperties: { type: string } }
        responseBody: { oneOf: [{ $ref: '#/components/schemas/HttpBody' }, { type: 'null' }] }
    HttpBody:
      type: object
      required: [text, truncated]
      properties: { text: { type: string }, truncated: { type: boolean, description: 'Cut at 65536 UTF-8 bytes, or only its size kept.' } }
    RequestExamples:
      type: object
      description: '{ examples: { name, call, body: TestCallWrite without installationId }[] } (contracts integration/http/console.ts).'
      required: [examples]
      properties:
        examples:
          type: array
          items:
            type: object
            required: [name, call, body]
            properties: { name: { type: string }, call: { type: string }, body: { $ref: '#/components/schemas/TestCallWrite' } }
    OwnedIntegrationPage: { type: object, description: 'A page of OwnedIntegration with the total the filters match (contracts integration/http/publisher.ts).' }
    TestCases: { type: object, description: '{ items: TestCase[] } (contracts integration/http/console.ts).' }
    TestCallWrite:
      type: object
      description: TestCallWrite (contracts integration/http/console.ts).
      required: [version, call, input, apply]
      additionalProperties: false
      properties:
        version: { type: string }
        installationId: { type: string, description: "Left out, the workspace's installation of the integration is used." }
        call: { type: string, examples: [lookup, send.file] }
        input: { description: "The call's input as the protocol has it." }
        apply: { type: boolean, const: false, description: 'Applying effects from the console is refused.' }
        caseId: { type: string, description: "A saved case's name: its stubs answer for the tool. Left out, the call reaches the tool for real against the Test environment." }
    TestRun: { type: object, description: 'TestRun (contracts integration/http/console.ts).' }
    Environments: { type: object, description: '{ integrationId, environments: { test, live }: EnvVariable[], missing: { test, live }: string[] } (contracts integration/http/environments.ts).' }
    EnvVariableWrite: { type: object, description: "{ value: string (trimmed, 1 to 16384), kind?: 'value' | 'secret' } (contracts integration/http/environments.ts)." }
    PlanId: { type: string, enum: [startup, business, enterprise], description: 'An organisation''s plan (ADR 0031).' }
    SeatId: { type: string, enum: [viewer, casual, handson, avid], description: 'A person''s seat in an organisation. Viewer is free and read only.' }
    Standing: { type: string, enum: [trial, active, past_due, lapsed], description: 'trial 14 days; past_due a payment failed, everything still works for 7 days; lapsed read only until someone pays, nothing deleted.' }
    LimitState: { type: object, required: [used, allowed], properties: { used: { type: integer }, allowed: { type: [integer, 'null'], description: null is no limit } } }
    SeatCounts: { type: object, properties: { viewer: { type: integer }, casual: { type: integer }, handson: { type: integer }, avid: { type: integer } } }
    LapsedRefusal:
      type: object
      description: 'The details of a 402 lapsed refusal (ADR 0031 decision 16): the organisation stopped paying, so every write is refused until a payment goes through. Reading, searching, exporting, the person''s own settings, paying and deleting a workspace still work.'
      required: [standing, since]
      properties: { standing: { const: lapsed }, since: { type: integer, description: When it went read only (ms). } }
    QuotaRefusal:
      description: The details of a 402 quota refusal (ADR 0031 decision 11). unlocks is the cheapest seat or plan that would allow it, null when nothing sold would.
      oneOf:
        - { type: object, required: [kind, key, plan, seat, unlocks], properties: { kind: { const: feature }, key: { type: string }, plan: { $ref: '#/components/schemas/PlanId' }, seat: { $ref: '#/components/schemas/SeatId' }, unlocks: { type: [object, 'null'] } } }
        - { type: object, required: [kind, key, plan, seat, used, allowed, unlocks], properties: { kind: { const: limit }, key: { type: string, enum: [captures_per_month, workspaces, storage] }, plan: { $ref: '#/components/schemas/PlanId' }, seat: { $ref: '#/components/schemas/SeatId' }, used: { type: integer }, allowed: { type: integer }, unlocks: { type: [object, 'null'] } } }
    Entitlements:
      type: object
      description: GET /entitlements (contracts v1/entitlements.ts).
      required: [plan, seat, standing, trialEndsAt, features, limits, capturesResetAt]
      properties:
        plan: { $ref: '#/components/schemas/PlanId' }
        seat: { $ref: '#/components/schemas/SeatId' }
        standing: { $ref: '#/components/schemas/Standing' }
        trialEndsAt: { type: [integer, 'null'] }
        features: { type: object, description: 'Every feature key, true or false: capture, collaborate, share, inspect, agents, developer, build_integrations, bulk_send, organise, link_controls.', additionalProperties: { type: boolean } }
        limits: { type: object, properties: { captures_per_month: { $ref: '#/components/schemas/LimitState' }, workspaces: { $ref: '#/components/schemas/LimitState' }, storage: { $ref: '#/components/schemas/LimitState' } } }
        capturesResetAt: { type: integer }
    Organisation: { type: object, description: 'GET /organisation (contracts v1/organisation.ts): id, name, owner, plan, standing, trialEndsAt, period, currency, workspaces and storage as LimitState, seats as SeatCounts.' }
    OrganisationPatch: { type: object, additionalProperties: false, minProperties: 1, properties: { name: { type: string, minLength: 1, maxLength: 80 }, ownerId: { type: string, description: 'Hands the organisation to this person: an owner or admin of one of its workspaces.' } } }
    MeOrganisation:
      type: object
      description: "The caller's organisation, their seat in it, its standing with the dates that go with it, and whether the caller owns it (the one person who can pay, and so the only one told about money)."
      required: [id, name, plan, standing, seat, trialEndsAt, readOnlyAt, ownedByYou]
      properties:
        id: { type: string }
        name: { type: string }
        plan: { $ref: '#/components/schemas/PlanId' }
        standing: { $ref: '#/components/schemas/Standing' }
        seat: { $ref: '#/components/schemas/SeatId' }
        trialEndsAt: { type: [integer, 'null'], description: When the trial ends (ms); null outside the trial. }
        readOnlyAt: { type: [integer, 'null'], description: 'Past due: when it will go read only; lapsed: when it did; null otherwise.' }
        ownedByYou: { type: boolean, description: The caller owns the organisation. }
    SeatWrite: { type: object, required: [seat], properties: { seat: { $ref: '#/components/schemas/SeatId' } } }
    Error:
      type: object
      properties: { error: { type: object, required: [code, message], properties: { code: { type: string }, message: { type: string }, details: {} } } }
    DeleteConfirmation:
      type: object
      description: >-
        The word typed again to confirm a delete: the caller's email address for an account (at most 320 characters),
        the slug for a workspace, the name for a project. Sent as the JSON body so it is never part of the address.
      required: [confirm]
      additionalProperties: false
      properties: { confirm: { type: string, minLength: 1, maxLength: 500 } }
    PageBase:
      type: object
      required: [items, nextCursor]
      properties: { items: { type: array }, nextCursor: { type: [string, 'null'] } }
    Count: { type: object, properties: { id: { type: string }, name: { type: string }, count: { type: integer } } }
    Role: { type: string, enum: [owner, admin, member], description: 'What someone may manage in a workspace: Owner, Admin, Member. What they can do with captures is their seat (SeatId), not their role.' }
    Tool: { type: string, enum: [lasso, rect, pen, highlight, font, color, element, mark, edit, spacing], description: '`spacing` paints one side of an element''s box (Spacing), `element` keeps one element, `mark` marks words on the page (Mark text), `edit` changes words in place (Live text).' }
    ItemStatus: { type: string, enum: [new, sent, fixed] }
    AttachmentRole: { type: string, enum: [crop, viewport, pin, clip, frames, voice, thumb], description: '`thumb` is a smaller copy of the attachment named by its `renditionOf`, made on the device at capture time. Thumbs are listed only when asked for by role; `size=thumb` links them in place of the original. A live text (`detail.tool` `edit`) has a `crop` like any capture: the page with the change shown as a word diff.' }
    ShareAudience: { type: string, enum: [anyone, workspace, signed_in] }
    PersonRef: { type: object, properties: { id: { type: string }, name: { type: string }, avatarUrl: { type: [string, 'null'] } } }
    LabelRef: { type: object, properties: { id: { type: string }, name: { type: string }, color: { type: string } } }
    Me:
      type: object
      properties:
        user: { $ref: '#/components/schemas/PersonRef' }
        workspace: { $ref: '#/components/schemas/Workspace' }
        role: { $ref: '#/components/schemas/Role' }
        workspaces: { type: array, description: "Every workspace the caller belongs to, with its organisation's id and name (a person may be in several organisations). `own` is true for exactly the caller's own personal workspace (the one made for them, shown when no `X-Workspace` is sent); another person's personal workspace they were invited into is never `own`.", items: { type: object, properties: { id: { type: string }, name: { type: string }, kind: { type: string, enum: [personal, team] }, organisationId: { type: string }, organisationName: { type: string }, role: { $ref: '#/components/schemas/Role' }, own: { type: boolean } } } }
        organisation: { $ref: '#/components/schemas/MeOrganisation' }
        canInvite: { type: boolean, description: 'Whether the caller may invite people to this workspace: admins and owners always, members when the workspace lets members invite.' }
    Onboarding:
      type: object
      properties:
        aboutYouDone: { type: boolean }
        practiceDone: { type: boolean }
        checklistHidden: { type: boolean }
        steps:
          type: array
          description: Only the steps the caller can take, in this order. A Viewer seat gets no capture steps; a member gets `invite_team` only when the workspace lets members invite.
          items: { type: object, properties: { key: { type: string, enum: [extension, first_item, invite_team] }, done: { type: boolean }, doneAt: { type: [integer, 'null'] } } }
        doneCount: { type: integer }
        guidesEnded: { type: array, description: 'The guides the caller is finished with in this workspace, each once. Empty until one is ended, and again after `guidesReset`.', items: { $ref: '#/components/schemas/GuideKey' } }
    GuideKey: { type: string, enum: [first_capture, tool_intros, tool_lasso, tool_rect, tool_pen, tool_highlight, tool_font, tool_color, tool_element, tool_mark, tool_edit, tool_spacing], description: 'A guide: the bubbles that walk a person through something the first time they do it. `first_capture` is the tour; `tool_<kind>` is that tool''s intro; `tool_intros` is every tool''s intro at once.' }
    OnboardingPatch:
      type: object
      additionalProperties: false
      minProperties: 1
      properties:
        firstName: { type: string, minLength: 1, maxLength: 40, description: Trimmed }
        lastName: { type: string, maxLength: 40, description: Trimmed }
        work: { $ref: '#/components/schemas/Work' }
        workspaceName: { type: string, minLength: 2, maxLength: 60, description: 'Trimmed. Owner only, during first run.' }
        checklistHidden: { type: boolean }
        practiceSkipped: { type: boolean }
        guideEnded: { $ref: '#/components/schemas/GuideKey', description: 'Ends this guide for the caller. Not together with `guidesReset`.' }
        guidesReset: { type: boolean, enum: [true], description: 'Shows every guide again. Not together with `guideEnded`.' }
    Work: { type: string, enum: [design, product, marketing, testing, engineering, founder, other] }
    Practice:
      type: object
      required: [shopUrl, faults]
      properties:
        shopUrl: { type: string, format: uri }
        faults: { type: array, items: { type: object, required: [n, hint, found, itemId], properties: { n: { type: integer }, hint: { type: string }, found: { type: boolean }, itemId: { type: [string, 'null'] } } } }
    InboxItem:
      type: object
      properties:
        id: { type: string }
        kind: { type: string, enum: [mention, assigned, unassigned, comment, sent, fixed, reopened, labelled, link_opened, link_changed, send_failed] }
        read: { type: boolean }
        at: { type: integer }
        actor: { $ref: '#/components/schemas/PersonRef', description: 'Who caused it; `anonymous` (Someone) for a link opened without a session, `tool:<installation>` for a tool' }
        message: { type: string, description: 'Short line, e.g. Sam mentioned you: "can you check on a phone?". The actor is named as they are named now; someone no longer in the workspace reads "Former member". No name is stored with the item' }
        cleared: { type: boolean }
        snoozedUntil: { type: [integer, 'null'] }
        item: { type: object, description: The item this is about, properties: { id: { type: string }, kind: { $ref: '#/components/schemas/ItemKind' }, ref: { type: string }, title: { type: string }, projectId: { type: string } } }
    InboxPage: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { properties: { items: { type: array, items: { $ref: '#/components/schemas/InboxItem' } } } }] }
    ItemSummary:
      type: object
      properties:
        id: { type: string }
        ref: { type: string, examples: [CAP-128] }
        kind: { $ref: '#/components/schemas/ItemKind' }
        title: { type: string }
        status: { $ref: '#/components/schemas/ItemStatus' }
        projectId: { type: string }
        group: { type: [string, 'null'], description: Page key when group=page }
        itemGroup: { description: 'The run of saves it was made in (a capture group, ADR 0026) and its number there; null for an item saved on its own', oneOf: [{ type: object, required: [id, n], properties: { id: { type: string }, n: { type: integer, minimum: 1 } } }, { type: 'null' }] }
        labelIds: { type: array, items: { type: string } }
        createdBy: { $ref: '#/components/schemas/PersonRef' }
        createdAt: { type: integer }
        thumbUrl: { type: [string, 'null'], description: Short-lived }
        counts: { type: object, properties: { comments: { type: integer } } }
        capture: { description: "The capture kind's part of the row; null for any other kind", oneOf: [{ $ref: '#/components/schemas/CaptureRow' }, { type: 'null' }] }
    ItemPage: { allOf: [{ $ref: '#/components/schemas/PageBase' }, { required: [groupTotals, groups], properties: { items: { type: array, description: 'A run of saves (a capture group, ADR 0026) is one entry: only its first item in list order is here, its items are in `groups`, and its later items are skipped on this and later pages.', items: { $ref: '#/components/schemas/ItemSummary' } }, groups: { type: object, description: "Each run of saves this page shows, by group id: its name (null until named) and its items the filters let through, in the order they were saved.", additionalProperties: { type: object, required: [name, members], properties: { name: { type: [string, 'null'] }, members: { type: array, items: { $ref: '#/components/schemas/ItemSummary' } } } } }, groupTotals: { type: object, additionalProperties: { type: integer }, description: "Grouped, how many captures the whole list (same filters, every page) holds in each group this page shows, keyed by the page's address or the project id. Empty when not grouped." } } }] }
    ItemView:
      allOf:
        - $ref: '#/components/schemas/ItemSummary'
        - type: object
          properties:
            etag: { type: string }
            description: { type: string }
            labels: { type: array, items: { $ref: '#/components/schemas/LabelRef' } }
            assignee: { oneOf: [{ $ref: '#/components/schemas/PersonRef' }, { type: 'null' }] }
            filed: { type: [object, 'null'], description: 'Where it was filed, as the typed outcome; itemIds names every capture of that send', properties: { installationId: { type: string }, outcome: { $ref: '#/components/schemas/Outcome' }, itemIds: { type: array, items: { type: string } } } }
            parts: { type: object, description: Counts for tab badges, properties: { attachments: { type: integer }, comments: { type: integer } } }
            prevId: { type: [string, 'null'] }
            nextId: { type: [string, 'null'] }
            position: { type: object, properties: { index: { type: integer }, total: { type: integer } } }
            capture: { description: "The capture kind's part of the page; null for any other kind", oneOf: [{ $ref: '#/components/schemas/CaptureSection' }, { type: 'null' }] }
    ItemKind: { type: string, enum: [capture], description: "What an item is. Each kind brings its own section to a row, a view and a report." }
    CaptureRow:
      type: object
      description: What a capture adds to a list row.
      required: [tool, page, errors, failedRequests]
      properties:
        tool: { $ref: '#/components/schemas/Tool' }
        page: { type: object, properties: { url: { type: string }, title: { type: string } } }
        errors: { type: integer, description: Console errors recorded with it }
        failedRequests: { type: integer }
    CaptureSection:
      description: What a capture adds to an item's page.
      allOf:
        - $ref: '#/components/schemas/CaptureRow'
        - type: object
          properties:
            environment:
              type: object
              description: >-
                The browser, the system, the window and the connection, each only when it is known. A capture made
                before the browser reported these about itself has the browser's name and major version and the
                system's name, read from its user agent.
              properties:
                browser: { $ref: '#/components/schemas/DeviceBrowser' }
                os: { $ref: '#/components/schemas/DeviceSystem' }
                viewport: { type: object, properties: { width: { type: integer }, height: { type: integer }, zoom: { type: number } } }
                connection: { $ref: '#/components/schemas/DeviceConnection' }
            element: { type: [object, 'null'], properties: { selector: { type: string }, component: { type: string }, text: { type: string } } }
            marks:
              type: array
              description: Words marked with the Mark text tool, in the order they were marked, with their notes. Empty for every other tool.
              items: { type: object, required: [text, selector], properties: { text: { type: string, maxLength: 2000 }, selector: { type: string, maxLength: 1000 }, note: { type: string, maxLength: 500 } } }
            change:
              type: [object, 'null']
              description: A live text's change, the element, its text before and after, and the words given a style (`styles`). Its pictures are the `before` and `desired` attachments. Null for every other tool.
              required: [selector, from, to]
              properties: { selector: { type: string, maxLength: 1000 }, from: { type: string, maxLength: 5000 }, to: { type: string, maxLength: 5000 }, styles: { type: array, maxItems: 50, description: 'Words given a style with the Live text toolbar, only what was asked for.', items: { type: object, additionalProperties: false, required: [text], properties: { text: { type: string, maxLength: 500 }, bold: { const: true }, italic: { const: true }, underline: { const: true }, color: { type: string, pattern: '^#[0-9a-fA-F]{6}$' } } } } }
            spacing:
              type: [object, 'null']
              description: The Spacing tool's element, the side its pictures show, its padding and margin (top, right, bottom, left, CSS pixels; a margin may be negative) and a flex or grid container's row and column gaps. Null for every other tool.
              required: [selector, show, padding, margin]
              properties:
                selector: { type: string, maxLength: 1000 }
                show: { type: string, enum: [padding, margin] }
                padding: { type: array, minItems: 4, maxItems: 4, items: { type: number } }
                margin: { type: array, minItems: 4, maxItems: 4, items: { type: number } }
                gap: { type: object, required: [row, column], properties: { row: { type: number, minimum: 0 }, column: { type: number, minimum: 0 } } }
            parts: { type: object, description: Counts for the Console and Network tab badges, properties: { console: { type: integer }, network: { type: integer } } }
    DeviceBrowser:
      type: object
      description: The browser's own name and version, e.g. Chrome 157.0.8103.50 (only the major version on older captures).
      required: [name, version]
      properties:
        name: { type: string, maxLength: 60 }
        version: { type: string, maxLength: 40 }
    DeviceSystem:
      type: object
      description: The system, its version where the browser reports a real one, and the processor family.
      required: [name]
      properties:
        name: { type: string, maxLength: 40, description: 'macOS, Windows, Linux, ChromeOS, Android or iOS' }
        version: { type: string, maxLength: 40 }
        architecture: { type: string, maxLength: 20, description: 'arm or x86' }
    DeviceConnection:
      type: object
      description: The connection as the browser estimated it when the capture was made.
      properties:
        effectiveType: { type: string, enum: [slow-2g, 2g, 3g, 4g] }
        downlinkMbps: { type: number, minimum: 0, description: Megabits per second down; browsers report no more than 10 }
        rttMs: { type: number, minimum: 0, description: Round-trip time in milliseconds }
    CaptureCreate:
      type: object
      required: [id, projectId, createdAt, pageUrl, pageTitle, detail, attachments, title, description]
      properties:
        id: { type: string, pattern: '^[A-Za-z0-9][A-Za-z0-9_-]{0,99}$' }
        projectId: { type: string }
        createdAt: { type: integer, description: ms since epoch }
        pageUrl: { type: string }
        pageTitle: { type: string }
        group: { type: object, required: [id, n], description: "The run of saves it belongs to (a tool used again and again until Done): a UUID made on the device, claimed by the workspace the first time an item names it (another workspace's is refused, 409), and the item's number in the run", properties: { id: { type: string, format: uuid }, n: { type: integer, minimum: 1, maximum: 50 } } }
        detail: { type: object, description: 'The tool and what it drew: `{ tool: rect }`, `{ tool: lasso, path }`, `{ tool: pen, ink }` and so on. `{ tool: element, selector }` names the element kept; `{ tool: mark, marks }` lists 1 to 20 marked words, each `{ text, selector, rects, note? }`; `{ tool: edit, change }` is a live text, `change` being `{ selector, from, to, styles? }` with `from` and `to` different or at least one styled run (`{ text, bold?, italic?, underline?, color? }`), its `before` and `desired` pictures attached; `{ tool: spacing, spacing }` is `{ selector, show, padding, margin, gap? }`, `show` being `padding` or `margin` (the side painted on the pictures) and `padding` and `margin` four numbers each in CSS pixels, top, right, bottom, left (a margin may be negative); `gap` is a flex or grid container''s `{ row, column }` gaps between its children' }
        rect: { type: object, properties: { x: { type: number }, y: { type: number }, width: { type: number }, height: { type: number } } }
        attachments:
          type: array
          maxItems: 24
          items:
            type: object
            required: [id, role, contentType, bytes, assetId]
            properties: { id: { type: string }, role: { type: string }, contentType: { type: string }, bytes: { type: integer }, width: { type: integer }, height: { type: integer }, durationMs: { type: integer }, renditionOf: { type: string, description: 'For a thumb: the attachment it is a smaller copy of' }, assetId: { type: string, description: The asset id `POST /assets/upload` answered for this attachment } }
        title: { type: string, maxLength: 200 }
        description: { type: string, maxLength: 10000 }
        labelIds: { type: array, maxItems: 20, items: { type: string } }
        newLabels: { type: array, maxItems: 10, items: { type: object, required: [name], properties: { name: { type: string, maxLength: 40 }, color: { type: string, pattern: '^#[0-9a-fA-F]{6}$' } } } }
        context:
          type: object
          description: 'Page context: URL, viewport, element, diagnostics and the timeline they were read from, and what the browser says about itself'
          properties:
            environment:
              type: object
              description: The browser, the system and the connection as the browser reports them (User-Agent Client Hints, Network Information API). Every part is optional; nothing is guessed.
              properties:
                browser: { $ref: '#/components/schemas/DeviceBrowser' }
                os: { $ref: '#/components/schemas/DeviceSystem' }
                connection: { $ref: '#/components/schemas/DeviceConnection' }
    CaptureCreated:
      type: object
      required: [item, labelsRefused, created]
      properties:
        item: { $ref: '#/components/schemas/ItemView' }
        labelsRefused: { type: array, items: { type: string } }
        created: { type: boolean }
    ItemPatch:
      type: object
      minProperties: 1
      properties:
        title: { type: string, maxLength: 200 }
        description: { type: string, maxLength: 10000 }
        labelIds: { type: array, maxItems: 20, items: { type: string } }
        status: { $ref: '#/components/schemas/ItemStatus' }
        assigneeId: { type: [string, 'null'] }
        projectId: { type: string }
    AttachmentView:
      type: object
      properties: { id: { type: string }, role: { $ref: '#/components/schemas/AttachmentRole' }, contentType: { type: string }, width: { type: integer }, height: { type: integer }, url: { type: string }, expiresAt: { type: integer, description: When the link stops working. }, keptUntil: { type: [integer, 'null'], description: "When the plan's retention removes the bytes; null on a plan that keeps attachments." } }
    AttachmentList:
      type: object
      properties:
        items: { type: array, items: { $ref: '#/components/schemas/AttachmentView' } }
        removed: { type: array, description: Attachments the plan's retention has already removed., items: { type: object, properties: { id: { type: string }, role: { $ref: '#/components/schemas/AttachmentRole' }, removedAt: { type: integer } } } }
        retentionDays: { type: [integer, 'null'], description: "The plan's retention window in days; null when the plan keeps attachments." }
    ConsoleEvent:
      type: object
      properties: { id: { type: string }, kind: { type: string }, level: { type: string }, offsetMs: { type: integer }, message: { type: string }, source: { type: [string, 'null'], examples: ['product-card.js:88:21'] }, stack: { type: [string, 'null'] } }
    NetworkRequest:
      type: object
      properties: { id: { type: string }, method: { type: string }, url: { type: string, description: 'Without query string or fragment; `?…` marks that one was there.' }, status: { type: integer, description: '0 when the request failed, -1 when not known (in flight at capture, or a cross-origin resource).' }, type: { type: string }, bytes: { type: [integer, 'null'] }, cached: { type: boolean }, startMs: { type: integer }, durationMs: { type: integer } }
    NetworkRequestDetail:
      allOf:
        - $ref: '#/components/schemas/NetworkRequest'
        - properties: { requestHeaders: { type: object, additionalProperties: { type: string } }, responseHeaders: { type: object, additionalProperties: { type: string } }, timing: { type: object, additionalProperties: { type: integer } } }
    CaptureActions:
      type: object
      properties:
        canEdit: { type: boolean }
        canSend: { type: boolean }
        canShare: { type: boolean }
        canDelete: { type: boolean }
    Comment:
      type: object
      properties: { id: { type: string }, author: { $ref: '#/components/schemas/PersonRef' }, body: { type: string }, mentions: { type: array, items: { type: string } }, createdAt: { type: integer }, editedAt: { type: [integer, 'null'] } }
    JoinRequest:
      type: object
      required: [code]
      properties: { code: { type: string, minLength: 1, maxLength: 200, description: 'The code from an invite link or email.' } }
    AccessRequestWrite:
      type: object
      required: [via]
      properties:
        via:
          oneOf:
            - { type: object, required: [kind, code], properties: { kind: { type: string, enum: [invite] }, code: { type: string, minLength: 1, maxLength: 200 } } }
            - { type: object, required: [kind, token], properties: { kind: { type: string, enum: [share] }, token: { type: string, minLength: 1, maxLength: 200 } } }
    AccessRequest:
      type: object
      description: One person asking to join, as the workspace's admins see it.
      properties: { id: { type: string }, person: { $ref: '#/components/schemas/PersonRef' }, email: { type: string }, via: { type: string, enum: [invite, share] }, requestedAt: { type: integer } }
    Activity:
      type: object
      description: One history line. Word it from `kind` and `detail`; `text` is the server's own sentence and is not meant to be read apart. A tool's own news has the tool as `actor`; a shared link opened without signing in has `Someone`.
      properties:
        id: { type: string }
        kind: { type: string, enum: [created, sent, labelled, assigned, fixed, link_opened, edited] }
        actor: { $ref: '#/components/schemas/PersonRef' }
        at: { type: integer }
        text: { type: string }
        url: { type: [string, 'null'] }
        detail:
          description: The line's parts, of the same kind as the line. Null on a line recorded before its parts were kept.
          oneOf:
            - { type: 'null' }
            - { $ref: '#/components/schemas/ActivityDetail' }
    TrackerRef:
      type: object
      description: A tool as a history line names it.
      properties: { id: { type: string, description: The installation }, name: { type: [string, 'null'], description: "Its integration's name; null once the workspace no longer has it." } }
    ActivityDetail:
      description: What a history line is about, discriminated on `kind`.
      oneOf:
        - { type: object, required: [kind], properties: { kind: { type: string, enum: [created] } } }
        - { type: object, required: [kind, tracker, reference], properties: { kind: { type: string, enum: [sent] }, tracker: { $ref: '#/components/schemas/TrackerRef' }, reference: { type: string, description: 'The item as the tool refers to it, e.g. `#214` or `ABC-12`; empty for an opaque id.' } } }
        - { type: object, required: [kind], properties: { kind: { type: string, enum: [labelled] } } }
        - { type: object, required: [kind, assignee], properties: { kind: { type: string, enum: [assigned] }, assignee: { description: 'Null when the assignee was removed.', oneOf: [{ type: 'null' }, { $ref: '#/components/schemas/PersonRef' }] } } }
        - type: object
          required: [kind, closedBy]
          properties:
            kind: { type: string, enum: [fixed] }
            closedBy:
              type: [object, 'null']
              description: What at a tool marked the capture fixed; null when a person did.
              properties: { tracker: { $ref: '#/components/schemas/TrackerRef' }, target: { type: string, description: 'The repository, project or board.' }, reference: { type: string }, event: { type: string, enum: [closed, merged] } }
        - { type: object, required: [kind], properties: { kind: { type: string, enum: [link_opened] } } }
        - { type: object, required: [kind, status], properties: { kind: { type: string, enum: [edited] }, status: { description: 'The status it was set to; null when its words or project were edited.', oneOf: [{ type: 'null' }, { $ref: '#/components/schemas/ItemStatus' }] } } }
    Share:
      type: object
      properties: { id: { type: string }, url: { type: [string, 'null'], description: 'The public link; answered only when it is made (only its digest is kept), null afterwards.' }, audience: { $ref: '#/components/schemas/ShareAudience' }, createdBy: { $ref: '#/components/schemas/PersonRef' }, views: { type: [integer, 'null'], description: 'Opens by anyone but the maker; the maker checking their own link is not counted. Null when the plan has no link_controls.' }, firstOpenedAt: { type: [integer, 'null'], description: 'The first open by anyone but the maker; null when the plan has no link_controls.' }, expiresAt: { type: [integer, 'null'] }, shows: { type: array, items: { $ref: '#/components/schemas/ShareExtra' }, description: "What the link's page shows beyond the capture itself. Empty unless whoever shared chose otherwise." } }
    ShareExtra:
      type: string
      enum: [pictures, info, console, network]
      description: 'A part of the capture a shared link may also show: its pictures and recording, the rest of the Info tab, the Console, or the Network. The last two can hold private details of the page.'
    ProjectWrite:
      type: object
      properties: { name: { type: string, minLength: 1, maxLength: 80 }, sites: { type: array, maxItems: 20, items: { type: string } } }
    ProjectSummary:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        sites: { type: array, items: { type: string } }
        sendsTo: { type: [string, 'null'], examples: [stride/storefront] }
        counts: { type: object, properties: { total: { type: integer }, new: { type: integer }, fixed: { type: integer } } }
        people: { type: object, properties: { preview: { type: array, maxItems: 3, items: { $ref: '#/components/schemas/PersonRef' } }, total: { type: integer } } }
        lastItemAt: { type: [integer, 'null'] }
        archived: { type: boolean }
        myRole: { type: string, enum: [lead, member, none], description: "The caller's own place on the project. Its lead may delete it without being an admin." }
    Project:
      allOf: [{ $ref: '#/components/schemas/ProjectSummary' }, { properties: { etag: { type: string }, createdAt: { type: integer } } }]
    ProjectPerson: { allOf: [{ $ref: '#/components/schemas/PersonRef' }, { properties: { lead: { type: boolean }, items: { type: integer } } }] }
    ProjectDestination:
      type: object
      properties: { projectId: { type: string }, projectName: { type: string }, installationId: { type: [string, 'null'] }, target: { type: [string, 'null'] }, sent: { type: integer } }
    Invitation:
      type: object
      description: "`email` invites carry the address they were sent to; `link` invites carry `note` (who it is for) and `url`."
      required: [id, channel, role, seat, invitedBy, createdAt, expiresAt]
      properties: { id: { type: string }, channel: { type: string, enum: [email, link] }, email: { type: string }, note: { type: string }, url: { type: string }, role: { $ref: '#/components/schemas/Role' }, seat: { $ref: '#/components/schemas/SeatId' }, invitedBy: { $ref: '#/components/schemas/PersonRef' }, createdAt: { type: integer }, expiresAt: { type: integer } }
    InviteRules:
      type: object
      properties: { adminsOnly: { type: boolean }, allowedDomain: { type: [string, 'null'] } }
    Member:
      allOf: [{ $ref: '#/components/schemas/PersonRef' }, { properties: { email: { type: string, description: Admins only }, role: { $ref: '#/components/schemas/Role' }, seat: { $ref: '#/components/schemas/SeatId' }, items: { type: integer }, lastSeenAt: { type: [integer, 'null'], description: 'When the person last used this workspace signed in, from the dashboard, the extension or an access key of theirs (ms since epoch, recorded at most once every five minutes); null when they never have.' } } }]
    LabelWrite:
      type: object
      properties: { name: { type: string, minLength: 1, maxLength: 40 }, color: { type: string, pattern: '^#[0-9a-f]{6}$' }, description: { type: string, maxLength: 120 } }
    Label: { allOf: [{ $ref: '#/components/schemas/LabelWrite' }, { properties: { id: { type: string }, uses: { type: integer }, position: { type: integer }, group: { type: [string, 'null'] }, builtIn: { type: boolean, description: 'One of the six labels every workspace starts with: renamed, recoloured and described freely, never deleted.' } } }] }
    Workspace:
      type: object
      properties: { id: { type: string }, name: { type: string }, slug: { type: string }, createdAt: { type: string }, deletable: { type: boolean, description: 'False for the workspace made for you at sign-up: it can be renamed, never deleted (DELETE /workspace answers 403).' } }
    SharingSettings:
      type: object
      properties: { linkAudience: { $ref: '#/components/schemas/ShareAudience' } }
    DataPolicy:
      type: object
      required: [retentionDays]
      properties: { retentionDays: { type: [integer, 'null'], minimum: 1, maximum: 36500, description: "Days the workspace keeps its files, counted from each upload; null keeps them" } }
    CapturePrivacy:
      type: object
      properties: { keepViewport: { type: boolean }, keepDiagnostics: { type: boolean } }
    Usage:
      type: object
      properties:
        plan: { $ref: '#/components/schemas/PlanId' }
        period: { type: object, properties: { from: { type: string, format: date }, to: { type: string, format: date } } }
        storage: { type: object, description: 'The organisation''s storage pool: every workspace''s files together.', properties: { usedBytes: { type: integer }, allowanceBytes: { type: [integer, 'null'] }, perSeatBytes: { type: [integer, 'null'], description: 'What one more paid seat adds.' } } }
        seats: { $ref: '#/components/schemas/SeatCounts' }
        items: { type: object, properties: { total: { type: integer }, thisPeriod: { type: integer } } }
    Billing:
      type: object
      properties:
        email: { type: [string, 'null'] }
        plan: { $ref: '#/components/schemas/PlanId' }
        status: { type: string, enum: [none, pending, active, past_due, cancelled] }
        interval: { type: [string, 'null'], enum: [monthly, yearly, null] }
        seats: { type: [integer, 'null'] }
        renewsAt: { type: [integer, 'null'] }
        pendingSince: { type: [integer, 'null'], description: 'When the checkout that left the subscription `pending` was started (ms since epoch); null in every other status. While it is recent, do not offer another checkout: the payment may still be on its way.' }
    Receipt:
      type: object
      properties: { id: { type: string }, at: { type: integer }, amount: { type: integer, description: minor units }, currency: { type: string, description: ISO 4217 }, reference: { type: string } }
    HostedLink:
      type: object
      description: A page at the payment provider. Card details never pass through this API.
      properties: { url: { type: string, format: uri } }
    PlanCatalogue:
      type: object
      description: What is sold (contracts catalogue.ts PublicCatalogue). Only chargeable currencies are listed.
      required: [currencies, plans, seats, prices, trial]
      properties:
        currencies: { type: object, description: 'By ISO 4217 code', additionalProperties: { type: object, properties: { symbol: { type: string }, chargeable: { type: boolean } } } }
        plans: { type: object, description: 'By PlanId', additionalProperties: { type: object, properties: { workspaces: { type: [integer, 'null'] }, storageGbPerPaidSeat: { type: integer }, features: { type: array, items: { type: string } }, selfServe: { type: boolean } } } }
        seats: { type: object, description: 'By SeatId', additionalProperties: { type: object, properties: { paid: { type: boolean }, capturesPerMonth: { type: [integer, 'null'] }, features: { type: array, items: { type: string } } } } }
        prices: { type: object, description: 'Plan, then paid seat, then period, then currency: minor units', additionalProperties: { type: object, additionalProperties: { type: object, properties: { monthly: { type: object, additionalProperties: { type: integer } }, yearly: { type: object, additionalProperties: { type: integer } } } } } }
        trial: { type: object, properties: { days: { type: integer }, plan: { $ref: '#/components/schemas/PlanId' }, seat: { $ref: '#/components/schemas/SeatId' } } }
    ExtensionSignIn:
      type: object
      required: [id, browser, workspace, connectedAt, lastUsedAt]
      properties:
        id: { type: string }
        browser: { type: string }
        workspace: { type: object, required: [id, name], properties: { id: { type: string }, name: { type: string } } }
        connectedAt: { type: number }
        lastUsedAt: { type: [number, 'null'] }
    ExtensionSignInList: { type: object, required: [items], properties: { items: { type: array, items: { $ref: '#/components/schemas/ExtensionSignIn' } } } }
    AccessKey:
      type: object
      properties: { id: { type: string }, name: { type: string }, last4: { type: string }, scopes: { type: array, items: { type: string } }, createdAt: { type: integer }, lastUsedAt: { type: [integer, 'null'] }, expiresAt: { type: [integer, 'null'] } }
    Profile:
      type: object
      required: [firstName, lastName, work, avatarUrl, email]
      properties:
        firstName: { type: string }
        lastName: { type: string }
        work: { oneOf: [{ $ref: '#/components/schemas/Work' }, { type: 'null' }] }
        avatarUrl: { type: [string, 'null'], readOnly: true, description: From the sign-in provider }
        email: { type: string, readOnly: true, description: From the sign-in provider }
    ProfilePatch:
      type: object
      additionalProperties: false
      minProperties: 1
      properties:
        firstName: { type: string, minLength: 1, maxLength: 40, description: Trimmed }
        lastName: { type: string, maxLength: 40, description: Trimmed }
        work: { $ref: '#/components/schemas/Work' }
    NotificationEvent:
      type: string
      enum: [mentioned, assigned, unassigned, commented, sent, fixed, reopened, labelled, link_opened, link_changed, send_failed, member_joined, join_requested, seat_changed, connection_broken]
      description: The last three are workspace events, offered to admins and owners only.
    MessageKind:
      type: string
      enum: [mentioned, assigned, unassigned, commented, sent, fixed, reopened, labelled, link_opened, link_changed, send_failed, member_joined, join_requested, seat_changed, connection_broken, invite, export_ready, export_failed, roundup, removed, request_approved, request_declined, organisation_owner, workspace_deleted, extension_connected, key_revoked, key_expiring, storage_nearly, storage_full]
      description: Every message the product sends; the notifying events, then the emails that go out whatever was chosen.
    MailLabList:
      type: object
      required: [items]
      properties:
        items:
          type: array
          items:
            type: object
            required: [kind, group, name, scope, canTurnOff, flow]
            properties:
              kind: { $ref: '#/components/schemas/MessageKind' }
              group: { type: string, examples: [Notifications] }
              name: { type: string, examples: [Mentioned] }
              scope: { type: string, enum: [workspace, organisation, account] }
              canTurnOff: { type: boolean, description: It follows the reader's notification settings. }
              flow: { $ref: '#/components/schemas/MailFlow' }
    MailFlow:
      type: object
      description: How the email reaches someone for real, so a tester can follow it and compare what arrives with the sample.
      required: [to, people, before, steps, check, note]
      properties:
        to: { type: string, description: Who gets it. }
        people: { type: integer, minimum: 1, maximum: 3, description: How many accounts it takes. }
        before: { type: array, items: { type: string }, description: What to set up first. }
        steps:
          type: array
          minItems: 1
          items:
            type: object
            required: [text, href]
            properties:
              text: { type: string }
              href: { type: [string, 'null'], description: The dashboard page the step happens on. }
        check: { type: string, description: 'What arrives, and at whose address.' }
        note: { type: [string, 'null'] }
    MailLabPreview:
      type: object
      required: [kind, subject, preview, html, text]
      properties:
        kind: { $ref: '#/components/schemas/MessageKind' }
        subject: { type: string }
        preview: { type: string, description: The line an inbox shows after the subject. }
        html: { type: string }
        text: { type: string }
    MailLabSent:
      type: object
      required: [to]
      properties: { to: { type: string, format: email, description: Your own address. } }
    DevMailDue:
      type: object
      required: [to]
      properties: { to: { type: string, format: email, description: The address the email goes to. } }
    DevConnection:
      type: object
      required: [installationId, name, icon, brokenAt]
      properties:
        installationId: { type: string }
        name: { type: string }
        icon: { type: [string, 'null'] }
        brokenAt: { type: [integer, 'null'], description: 'When the tool stopped accepting the connection; null while it works.' }
    DevStanding:
      type: object
      required: [standing, since, fixed]
      properties:
        standing: { $ref: '#/components/schemas/Standing' }
        since: { type: [integer, 'null'], description: 'When the trial ends, when the payment failed, or when it went read only; null while active.' }
        fixed: { type: boolean, description: 'A plan agreed with us is always active and cannot be moved.' }
    DevStandingChange:
      type: object
      required: [standing]
      properties: { standing: { $ref: '#/components/schemas/Standing' } }
    DevStates:
      type: object
      required: [standing, connections]
      properties:
        standing: { oneOf: [{ $ref: '#/components/schemas/DevStanding' }, { type: 'null' }], description: Null unless the caller owns the organisation. }
        connections: { type: array, items: { $ref: '#/components/schemas/DevConnection' } }
    DevConnectionChanged:
      type: object
      required: [connection]
      properties: { connection: { $ref: '#/components/schemas/DevConnection' } }
    DevServer:
      type: object
      required: [environment, publicUrl, signIn, integrations, store, version]
      properties:
        environment: { type: string, enum: [development, test, production] }
        publicUrl: { type: string }
        signIn: { type: string, enum: [dev, service] }
        integrations: { type: string, enum: [fixtures, built] }
        store: { type: string, enum: [postgres, memory] }
        version: { type: [string, 'null'] }
    Notifications:
      type: object
      required: [events, roundup]
      properties:
        events:
          type: object
          description: Keyed by event; every event offered to the caller's role, each with both channels.
          propertyNames: { $ref: '#/components/schemas/NotificationEvent' }
          additionalProperties: { type: object, required: [email, browser], properties: { email: { type: boolean }, browser: { type: boolean } } }
          examples: [{ mentioned: { email: true, browser: true }, assigned: { email: true, browser: false } }]
        roundup: { type: object, required: [enabled, day], properties: { enabled: { type: boolean }, day: { type: string, enum: [mon, tue, wed, thu, fri] } } }
    NotificationsPatch:
      type: object
      additionalProperties: false
      minProperties: 1
      properties:
        events:
          type: object
          description: Only the events and channels that change.
          propertyNames: { $ref: '#/components/schemas/NotificationEvent' }
          additionalProperties: { type: object, additionalProperties: false, properties: { email: { type: boolean }, browser: { type: boolean } } }
        roundup: { type: object, additionalProperties: false, properties: { enabled: { type: boolean }, day: { type: string, enum: [mon, tue, wed, thu, fri] } } }
    ExtensionSettings:
      type: object
      description: Every field resolved (the caller's choice or the default), cut to the workspace's capture privacy.
      required: [defaultProjectId, dock, detailStartsAs, recordFromPageLoad, attachViewport, attachDiagnostics, installs]
      properties:
        defaultProjectId: { type: [string, 'null'] }
        dock: { type: object, required: [tools, side], properties: { tools: { type: array, maxItems: 7, uniqueItems: true, description: 'The dock tool column in order: the four drawing tools and up to three tools pinned from More tools.', items: { type: string, enum: [lasso, rect, pen, highlight, font, color, element, measure, record, voice, mark, edit, spacing] } }, side: { type: string, enum: [left, right] } } }
        detailStartsAs: { type: string, enum: [text, voice] }
        recordFromPageLoad: { type: boolean, description: Needs the optional all-sites permission in Chrome }
        attachViewport: { type: boolean }
        attachDiagnostics: { type: boolean }
        installs: { type: array, readOnly: true, items: { type: object, required: [browser, version, lastSeenAt], properties: { browser: { type: string }, version: { type: string }, lastSeenAt: { type: integer } } } }
    ExtensionSettingsPatch:
      type: object
      additionalProperties: false
      minProperties: 1
      description: Only the fields that change. Cannot turn on anything the workspace's capture privacy has turned off.
      properties:
        defaultProjectId: { type: [string, 'null'], minLength: 1, maxLength: 100 }
        dock: { type: object, additionalProperties: false, minProperties: 1, properties: { tools: { type: array, maxItems: 7, uniqueItems: true, description: 'The dock tool column in order: the four drawing tools and up to three tools pinned from More tools.', items: { type: string, enum: [lasso, rect, pen, highlight, font, color, element, measure, record, voice, mark, edit, spacing] } }, side: { type: string, enum: [left, right] } } }
        detailStartsAs: { type: string, enum: [text, voice] }
        recordFromPageLoad: { type: boolean }
        attachViewport: { type: boolean }
        attachDiagnostics: { type: boolean }

    SiteDefault:
      type: object
      properties: { site: { type: string }, projectId: { type: [string, 'null'] }, installationId: { type: [string, 'null'] }, action: { type: [string, 'null'] }, target: { type: [string, 'null'] } }
    SendOptions:
      type: object
      properties:
        canSend: { type: boolean }
        signedIn: { type: boolean }
        connectUrl: { type: string, description: Integrations in the dashboard }
        lastUsed: { type: [object, 'null'], properties: { installationId: { type: string }, action: { type: string }, target: { type: string } } }
        items:
          type: array
          items:
            type: object
            properties:
              installationId: { type: string }
              integration: { type: object, properties: { id: { type: string }, name: { type: string }, icon: { type: [string, 'null'] } } }
              action: { type: string, description: The declared outcome's id }
              object: { type: string, enum: [issue, pull-request, merge-request] }
              group: { type: string, enum: [create, add_to] }
              needs: { type: string, enum: [target, open-change] }
              defaultTarget: { type: [string, 'null'] }
    SendForm:
      type: object
      properties:
        fields: { type: array, description: "The entry's form fields for the action (manifest `Field`: text, long-text, choice, switch, date)", items: { type: object, additionalProperties: true } }
        values: { type: object, additionalProperties: { oneOf: [{ type: string }, { type: boolean }, { type: array, items: { type: string } }] } }
        target: { type: [string, 'null'] }
        change: { type: [object, 'null'], properties: { required: { type: boolean }, detected: { type: [string, 'null'] } } }
    Filing:
      description: >-
        Shaped by `state`: a `sent` filing always has `result`, a `failed` one always has `error`, and one still on its
        way (`queued`, `uploading`, `sending`) has neither and may carry `progress`.
      oneOf:
        - allOf:
            - $ref: '#/components/schemas/FilingBase'
            - { type: object, properties: { state: { type: string, enum: [queued, uploading, sending] }, progress: { oneOf: [{ $ref: '#/components/schemas/FilingProgress' }, { type: 'null' }] }, result: { type: 'null' }, error: { type: 'null' } } }
        - allOf:
            - $ref: '#/components/schemas/FilingBase'
            - { type: object, properties: { state: { const: sent }, progress: { type: 'null' }, result: { $ref: '#/components/schemas/FilingResult' }, error: { type: 'null' } } }
        - allOf:
            - $ref: '#/components/schemas/FilingBase'
            - { type: object, properties: { state: { const: failed }, progress: { type: 'null' }, result: { type: 'null' }, error: { $ref: '#/components/schemas/FilingError' } } }
    FilingBase:
      type: object
      required: [id, itemIds, installationId, action, state, progress, result, error, by, at]
      properties:
        id: { type: string }
        itemIds: { type: array, minItems: 1, items: { type: string }, description: 'The captures this filing carries, in send order; they share the one outcome' }
        installationId: { type: string }
        action: { type: string }
        state: { type: string, enum: [queued, uploading, sending, sent, failed] }
        by: { $ref: '#/components/schemas/PersonRef' }
        at: { type: integer }
    FilingProgress:
      type: object
      properties: { done: { type: integer, minimum: 0 }, total: { type: integer, minimum: 0 }, text: { type: string, examples: ['Uploading pictures… 2 of 3'] } }
    FilingResult:
      type: object
      required: [outcome]
      properties: { outcome: { $ref: '#/components/schemas/Outcome' }, remoteStatus: { type: string, enum: [open, done, merged, closed] } }
    Outcome:
      type: object
      description: What a filing became, fully typed and self-describing; never prose.
      required: [id, action, object, target, ref, url]
      properties:
        id: { type: string }
        action: { type: string, enum: [create, comment] }
        object: { type: string, enum: [issue, pull-request, merge-request] }
        target: { type: string, examples: [stride/web] }
        ref:
          description: Discriminated on `scheme`; `key` is drawn as text, `id` is opaque and never drawn.
          oneOf:
            - { type: object, required: [scheme, prefix, number], properties: { scheme: { const: number }, prefix: { type: string, enum: ['#', '!'] }, number: { type: integer } } }
            - { type: object, required: [scheme, key], properties: { scheme: { const: key }, key: { type: string, examples: [ABC-12] } } }
            - { type: object, required: [scheme, id], properties: { scheme: { const: id }, id: { type: string } } }
        url: { type: string }
    FilingError:
      type: object
      required: [reason, retryable]
      description: >-
        Why it failed. A clear refusal ("<tool> refused it: …") created nothing; an unknown outcome ("<tool> did not
        answer clearly: …", or a filing that stopped while sending) may have, and the retry asks the installation for the
        earlier try (`send.find`) by the reference at the foot of the item before filing again. Filings never stay queued, uploading
        or sending: they are queued again or failed (retryable) after a few minutes.
      properties: { reason: { type: string, examples: ['Tracker refused it: the repository is archived.'] }, retryable: { type: boolean } }
