{
  "openapi": "3.1.0",
  "info": {
    "title": "openclone API",
    "version": "0.14.0",
    "description": "Public REST is /api/v1 (private, session + server-derived TenantContext). /api/revision is the independent deploy contract. Errors use the ErrorEnvelope; every response carries a server-generated request id.",
    "contact": {
      "email": "hi@openclone.fun"
    }
  },
  "servers": [
    {
      "url": "https://api.openclone.run",
      "description": "Production"
    },
    {
      "url": "https://api.dev.openclone.run",
      "description": "Development (noindex)"
    }
  ],
  "paths": {
    "/api/live": {
      "get": {
        "operationId": "liveness",
        "summary": "Check whether the application is running",
        "description": "Lightweight liveness check; does not check release metadata or dependencies.",
        "responses": {
          "200": {
            "description": "Application is running",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "head": {
        "operationId": "livenessHead",
        "responses": {
          "200": {
            "description": "Application is running"
          }
        }
      }
    },
    "/api/v1/auth/review-login": {
      "post": {
        "summary": "Optional fixed App Review test sign-in",
        "description": "Off unless APP_REVIEW_LOGIN_HASH is valid. Exact allow-listed same-host Origin and current consent required. Issues normal host-only session and CSRF cookies; password sessions grant no operator access.",
        "operationId": "reviewLogin",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "email",
                  "password",
                  "terms_version",
                  "privacy_version"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "description": "Only review@openclone.fun (normalized)"
                  },
                  "password": {
                    "type": "string",
                    "format": "password"
                  },
                  "terms_version": {
                    "type": "string"
                  },
                  "privacy_version": {
                    "type": "string"
                  },
                  "lang": {
                    "type": "string"
                  },
                  "time_zone": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in, example content seeded idempotently",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "created",
                    "return_to",
                    "csrf_token",
                    "request_id"
                  ],
                  "properties": {
                    "request_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "signed_in"
                      ]
                    },
                    "created": {
                      "type": "boolean"
                    },
                    "return_to": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "csrf_token": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid body or consent required"
          },
          "401": {
            "description": "Invalid address or password (same response)"
          },
          "403": {
            "description": "Forbidden origin"
          },
          "404": {
            "description": "Feature off; not_found"
          },
          "405": {
            "description": "POST required"
          },
          "409": {
            "description": "Terms or privacy version changed"
          },
          "413": {
            "description": "Request body too large"
          },
          "415": {
            "description": "JSON required"
          },
          "429": {
            "description": "Account or client network failure budget exhausted"
          },
          "503": {
            "description": "Database or demo seed unavailable"
          }
        }
      }
    },
    "/api/v1/imports": {
      "get": {
        "operationId": "listImports",
        "security": [
          {
            "session": []
          }
        ],
        "summary": "Latest 20 own-member import receipts",
        "responses": {
          "200": {
            "description": "Own receipt ids, state and created_at; no content"
          }
        }
      },
      "post": {
        "operationId": "previewImport",
        "security": [
          {
            "session": []
          }
        ],
        "summary": "Preview an owned ready CSV from private B2; no effects",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "file_id",
                  "source"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "file_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "message",
                      "document",
                      "statement"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Import id, preview/imported state, hash, source, format, subject, coverage, bounded items; authenticated and automatic_effects always false"
          },
          "400": {
            "description": "Correct unsupported format, source, mixed subject or invalid dates"
          },
          "404": {
            "description": "Missing or foreign file"
          },
          "409": {
            "description": "Replay conflict or limit"
          },
          "503": {
            "description": "B2 unavailable; no fallback"
          }
        }
      }
    },
    "/api/v1/imports/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getImport",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Fresh own-member preview after current file/hash/privacy checks"
          },
          "404": {
            "description": "Unknown or foreign import"
          },
          "409": {
            "description": "Privacy generation changed"
          }
        }
      }
    },
    "/api/v1/imports/{id}/confirm": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "confirmImport",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "hash",
                  "permission"
                ],
                "properties": {
                  "hash": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "permission": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Imported receipt after one atomic local commit; never sent or synced"
          },
          "409": {
            "description": "Hash changed, privacy changed, or preview older than 15 minutes"
          }
        }
      }
    },
    "/api/v1/handoffs": {
      "post": {
        "operationId": "officialHandoff",
        "security": [
          {
            "session": []
          }
        ],
        "summary": "Fixed official Google Drive link; no fetch, redirect or provider action",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "provider"
                ],
                "properties": {
                  "provider": {
                    "const": "google-drive"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Fixed https://drive.google.com/ link, state handoff, external_completion false"
          },
          "400": {
            "description": "Unlisted provider or arbitrary URL refused"
          }
        }
      }
    },
    "/api/v1/deadlines": {
      "get": {
        "operationId": "listDeadlines",
        "summary": "Read local waits; received is never completed",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Actor-scoped bounded wait list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "deadlines",
                    "request_id"
                  ],
                  "properties": {
                    "request_id": {
                      "type": "string"
                    },
                    "deadlines": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Obligations/$defs/wait"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/api/v1/deadlines/tick": {
      "post": {
        "operationId": "refreshDeadlines",
        "summary": "Explicitly evaluate local wakes under current authority; never sends a message",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current deadlines after the bounded idempotent pass"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/tasks/{taskId}/waits": {
      "parameters": [
        {
          "name": "taskId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "setTaskWait",
        "summary": "Create or replace a local reminder; current wait version required",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Obligations/$defs/wait_input"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved local wait and current deadlines"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/tasks/{taskId}/followups": {
      "parameters": [
        {
          "name": "taskId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "patch": {
        "operationId": "setLocalFollowupPolicy",
        "summary": "Set quiet hours and zero or one local reminders; no external authority",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Obligations/$defs/followup_policy"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current deadlines after policy update"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auto/candidates": {
      "get": {
        "operationId": "listAutoCandidates",
        "summary": "Source-linked private candidates and per-conversation settings; unavailable until gates pass",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "available, candidates and settings; no model invocation"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/api/v1/auto/settings": {
      "patch": {
        "operationId": "setAutoConversation",
        "summary": "Explicit monitored-conversation opt-in; current read grant and activation gates required",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Obligations/$defs/auto_setting"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Confirmed setting and new version"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auto/candidates/{candidateId}/accept": {
      "parameters": [
        {
          "name": "candidateId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "acceptAutoCandidate",
        "summary": "Accept a current source as a local task; no external approval",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current candidates after the decision"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auto/candidates/{candidateId}/ignore": {
      "parameters": [
        {
          "name": "candidateId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "ignoreAutoCandidate",
        "summary": "Ignore only this candidate; future monitoring stays enabled",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current candidates after the decision"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/research": {
      "delete": {
        "operationId": "clearResearch",
        "summary": "Delete every owned cached research comparison and its source snapshots; Files and Devices rows are never touched",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope deleted=<count>; requires CSRF and exact origin"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "operationId": "createResearch",
        "summary": "Read up to three user-selected public sources, with no discovery or inference",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "urls",
                  "terms_confirmed"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "urls": {
                    "type": "array",
                    "minItems": 0,
                    "maxItems": 3,
                    "items": {
                      "type": "string",
                      "maxLength": 2048,
                      "format": "uri"
                    }
                  },
                  "terms_confirmed": {
                    "const": true
                  },
                  "documents": {
                    "type": "array",
                    "minItems": 0,
                    "maxItems": 3,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "capture_id",
                        "revision",
                        "excerpt"
                      ],
                      "properties": {
                        "capture_id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "revision": {
                          "type": "integer",
                          "minimum": 1
                        },
                        "excerpt": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 79
                        }
                      }
                    }
                  },
                  "documents_confirmed": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Envelope research with id, task_id, reading/ready state, sources (final URL, access date, visible text hash, robots_tos_status, status, stale, byte span quote/hash) and documents (file page citation, access date, method, bounded quote, parse_state, extraction_error, stale), comparison=different/unknown, answer=unknown, discovery=unavailable, inference=disabled, mode=quoted_evidence. File excerpts are server-extracted bounded quotations rechecked against current file access on every read. Same id/input replays stored result without another fetch; reading may mean interrupted."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "Changed input, rate limit or current authority conflict"
          }
        }
      }
    },
    "/api/v1/research/{researchId}": {
      "parameters": [
        {
          "name": "researchId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getResearch",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Actor-owned encrypted ledger with current stale markers and has_previous boolean and fresh_after (the configured freshness threshold in seconds); legacy runs without a recorded predecessor return false"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "operationId": "deleteResearch",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope deleted=true; requires CSRF and exact origin"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/research/{researchId}/previous": {
      "parameters": [
        {
          "name": "researchId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "previousResearch",
        "summary": "Read the exact preceding comparison without fetching sources",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope research with the preceding actor-owned immutable run, original quotations, retrieval dates and unavailable source states. Both runs require current authority and privacy. No source fetch or new run. Internal reservation references are never returned."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "description": "No recorded predecessor, deleted or recreated predecessor, or inaccessible comparison"
          },
          "409": {
            "description": "Current privacy conflict"
          }
        }
      }
    },
    "/api/v1/research/{researchId}/refresh": {
      "parameters": [
        {
          "name": "researchId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refreshResearch",
        "summary": "Read the same public sources into a separate immutable comparison",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "terms_confirmed"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "New lowercase UUIDv4",
                    "distinct from researchId": null
                  },
                  "terms_confirmed": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "New actor-owned comparison with no inherited task binding. URLs derive from the owned original. An exact id/source retry replays the stored result without refetching; interrupted reads remain reading. Original evidence is unchanged. Requires CSRF and exact origin."
          },
          "400": {
            "description": "Invalid input or same id as the original"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "description": "Original missing or inaccessible"
          },
          "409": {
            "description": "Original incomplete, changed input, rate limit or current authority conflict"
          }
        }
      }
    },
    "/api/v1/tasks/{taskId}/sources": {
      "parameters": [
        {
          "name": "taskId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "taskResearch",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 512
            },
            "description": "Signed next_cursor from the previous page; bound to the current member generation and task/privacy scope."
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope sources={ids,more,next_cursor}. Up to 20 current actor-owned ready comparisons, ordered by creation time then id descending. When more=true, pass next_cursor to continue; terminal next_cursor is null. Deleting the boundary comparison does not invalidate continuation. Reads never fetch websites or change tasks."
          },
          "400": {
            "description": "Malformed cursor"
          },
          "404": {
            "description": "Task or cursor absent from current authorized scope; restart without cursor after scope or privacy changes."
          },
          "409": {
            "description": "Current task source authority revoked"
          }
        }
      },
      "post": {
        "operationId": "attachResearch",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "research_id"
                ],
                "properties": {
                  "research_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Actor-owned ledger linked to actor-owned task; never completes the task. Requires CSRF and exact origin."
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "operationId": "detachResearch",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "research_id"
                ],
                "properties": {
                  "research_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task association removed; the ledger stays readable and the task never completes. Requires CSRF and exact origin."
          },
          "404": {
            "description": "Ledger, task or association absent from current authorized scope"
          }
        }
      }
    },
    "/api/v1/drafts/{draftId}": {
      "parameters": [
        {
          "name": "draftId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getReplyDraft",
        "summary": "Current actor-owned immutable draft version, never a send receipt",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope {draft}: id, version, head_version, source_stale, payload (frozen trusted Gmail terms with source_revision digest and draft_revision), source_language, override, language, language_source (manual/source/unknown), approval_id, action_id, native_voice=false, attachments_available=false. An updated conversation marks the draft source_stale and clears approval_id; preview, confirm, edit and send refuse stale drafts with 409. Review the current source in Inbox and create a fresh immutable draft version via Reply. See docs/product/replies.md. No signed media URLs or media bytes."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "editReplyDraft",
        "summary": "Compare and append an encrypted version; invalidate earlier approval",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "version"
                ],
                "minProperties": 2,
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "recipient": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 320
                  },
                  "body": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 32000
                  },
                  "language": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Released locale override; null restores trusted source metadata, never UI locale."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{draft} with a new version, never sent. Exact-origin CSRF required."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "The exact version fence rejected the save, or the source is stale, already queued, or input is invalid. Reload and review the current draft; local input is not saved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "error"
                  ],
                  "properties": {
                    "error": {
                      "type": "object",
                      "required": [
                        "code",
                        "message_key",
                        "request_id",
                        "retryable",
                        "details"
                      ],
                      "properties": {
                        "code": {
                          "const": "reply_changed"
                        },
                        "message_key": {
                          "const": "error.conflict"
                        },
                        "request_id": {
                          "type": "string"
                        },
                        "retryable": {
                          "const": false
                        },
                        "details": {
                          "type": "object",
                          "additionalProperties": false
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/conversations/{conversationId}/drafts": {
      "parameters": [
        {
          "name": "conversationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "post": {
        "operationId": "admitReplyDraft",
        "summary": "Open an exact reviewed source draft (runtime gated)",
        "description": "Only an owned current inbound source with verified profile sender and bounded reply headers is eligible. Inbox returns reply_available and reply_source_revision (null when ineligible). Submit that opaque digest as source_revision; numeric provider history is not accepted. Repeated admission reopens the same draft. Changed content, headers, sender, consent or deletion invalidates drafts and retained approvals. Public Gmail activation remains gated.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "message_id",
                  "source_revision"
                ],
                "properties": {
                  "message_id": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "source_revision": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Actor-owned unapproved draft; no send or inference."
          },
          "400": {
            "description": "Malformed source identity/revision or extra fields."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "description": "Unknown, foreign or runtime-gated source."
          },
          "409": {
            "description": "Changed or ineligible source; refresh and review it again. Exact-origin CSRF required."
          }
        }
      }
    },
    "/api/v1/artifacts/workspace-capability": {
      "get": {
        "operationId": "workspaceCapability",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Capability bits available, create, update, readback, docs, sheets; all false until Google runtime admission. Preview route stays available for exact local text/cell previews. Save/Open stay hidden while unavailable."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/api/v1/artifacts/workspace-preview": {
      "post": {
        "operationId": "previewWorkspace",
        "summary": "Exact manual text or typed worksheet preview; no approval, queue or Google write",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Requires exact-origin CSRF. Validates WorkspacePlan bounds. Returns the unchanged plan, exact document text or typed cells/formulas and a signed two-decimal total. No model execution or saved state.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "plan"
                ],
                "properties": {
                  "plan": {
                    "type": "object",
                    "description": "kind=doc, title, text; or kind=sheet, title, currency (EUR/USD/GBP), items (1-500 literal label and exact amount strings)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "preview with plan, text, rows and total; never saved or verified in Drive"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "description": "Invalid plan or amount"
          }
        }
      }
    },
    "/api/v1/artifacts/{id}/status": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "workspaceStatus",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "action_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Save status checking/verified with official Drive file link only after verified provider readback; uncertain saves stay checking and offer reconciliation without duplicating."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "description": "Unknown artifact or action"
          },
          "409": {
            "description": "workspace_unavailable until Google runtime admission, or save conflict"
          }
        }
      }
    },
    "/api/v1/drafts": {
      "get": {
        "operationId": "draftListing",
        "summary": "Actor-owned manual drafts with head version and fenced outbox revision; no content",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope {drafts}: [{id, version, draft_revision, source_stale}] newest first, at most 50."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/api/v1/drafts/{draftId}/revisions": {
      "parameters": [
        {
          "name": "draftId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "draftHistory",
        "summary": "Read-only history of immutable draft versions with creation timestamps; no content",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Envelope {versions}: [{version, created_at}] in version order. Foreign drafts 404."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "description": "Unknown or foreign draft"
          }
        }
      }
    },
    "/api/v1/drafts/{draftId}/{operation}": {
      "parameters": [
        {
          "name": "draftId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "operation",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "enum": [
              "send",
              "translate",
              "attachments"
            ]
          }
        }
      ],
      "post": {
        "operationId": "gatedReplyOperation",
        "summary": "Unavailable until reviewed runtime, B2 media or AI admission respectively",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "reply_unavailable; no effects. Authentication and exact-origin CSRF required."
          }
        }
      }
    },
    "/api/v1/media/recordings": {
      "post": {
        "operationId": "gatedReplyRecording",
        "summary": "Outbound audio ingestion unavailable; reviewed microphone-to-text remains independent",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "reply_unavailable; no bytes retained. Authentication and exact-origin CSRF required."
          }
        }
      }
    },
    "/api/v1/conversations/{conversationId}/language": {
      "parameters": [
        {
          "name": "conversationId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "patch": {
        "operationId": "gatedConversationLanguage",
        "summary": "Conversation-wide preference awaits source-to-policy admission; draft override works independently",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "reply_unavailable; no preference changes. Authentication and exact-origin CSRF required."
          }
        }
      }
    },
    "/api/v1/artifacts": {
      "get": {
        "operationId": "listArtifacts",
        "summary": "Paginated own snapshots and reviewed invoice options",
        "description": "Scans 40 snapshots ordered by creation time and UUID descending. Returns artifacts, invoices and next_cursor (null at end). Unavailable snapshots are omitted; an empty page may still have a continuation. Dates are inclusive UTC days. Continue with the same filters.",
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "comparison",
                "form",
                "pdf",
                "bundle"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "file_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Owned ready source document"
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 512
            },
            "description": "Signed continuation bound to member and filters"
          }
        ],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/artifacts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getArtifact",
        "summary": "Private immutable snapshot with ownership-checked 120-second B2 links",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/comparisons": {
      "post": {
        "operationId": "createComparison",
        "summary": "Deterministic sourced comparison, never acceptance",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Same-origin CSRF required. Strict request keys and 16 KiB limit. Server-derived tenant and current member ownership; viewer, pause, privacy, source and membership fences apply. See docs/architecture/artifacts.md for exact per-operation fields and supported limits. Public AI and Drive writing remain unavailable.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/comparisons/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getComparison",
        "summary": "Read comparison; stale source revision refuses with 409",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/comparisons/{id}/note": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "saveComparisonNote",
        "summary": "Save a private note on an owned comparison",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Same-origin CSRF required. The note is encrypted with the comparison and limited to 500 Unicode characters; an empty string clears it.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "note"
                ],
                "properties": {
                  "note": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated comparison"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Forbidden"
          },
          "409": {
            "description": "Stale source"
          }
        }
      }
    },
    "/api/v1/forms": {
      "post": {
        "operationId": "inspectForm",
        "summary": "Inspect own private original; unsupported and locked remain unavailable",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Same-origin CSRF required. Strict request keys and 16 KiB limit. Server-derived tenant and current member ownership; viewer, pause, privacy, source and membership fences apply. See docs/architecture/artifacts.md for exact per-operation fields and supported limits. Public AI and Drive writing remain unavailable.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/forms/{id}/fields": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getFormFields",
        "summary": "Read supported fields and original source links",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/forms/{id}/fill": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "fillForm",
        "summary": "Create separate structurally checked and rendered PDF for visual review",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Same-origin CSRF required. Strict request keys and 16 KiB limit. Server-derived tenant and current member ownership; viewer, pause, privacy, source and membership fences apply. See docs/architecture/artifacts.md for exact per-operation fields and supported limits. Public AI and Drive writing remain unavailable.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/forms/{id}/options": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "pdfSourceOptions",
        "summary": "List bounded own reviewed sources and private mappings",
        "security": [
          {
            "session": []
          }
        ],
        "description": "See docs/architecture/pdf-source-autofill.md. Member ownership and current authority required; all writes require same-origin CSRF. No inference or external effects.",
        "responses": {
          "200": {
            "description": "Own private result; download URL absent until final exact-hash confirmation"
          },
          "400": {
            "description": "Invalid or unsupported binding or request"
          },
          "403": {
            "description": "Unknown or foreign reference, role denial or missing CSRF"
          },
          "409": {
            "description": "Source mapping or output changed; prepare and review again"
          }
        }
      }
    },
    "/api/v1/forms/{id}/mappings": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "pdfSaveMapping",
        "summary": "Create edit or delete a private immutable mapping revision",
        "security": [
          {
            "session": []
          }
        ],
        "description": "See docs/architecture/pdf-source-autofill.md. Member ownership and current authority required; all writes require same-origin CSRF. No inference or external effects.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own private result; download URL absent until final exact-hash confirmation"
          },
          "400": {
            "description": "Invalid or unsupported binding or request"
          },
          "403": {
            "description": "Unknown or foreign reference, role denial or missing CSRF"
          },
          "409": {
            "description": "Source mapping or output changed; prepare and review again"
          }
        }
      }
    },
    "/api/v1/forms/{id}/prepare": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "pdfPrepareSources",
        "summary": "Prepare exact supported values from explicitly selected current owned records",
        "security": [
          {
            "session": []
          }
        ],
        "description": "See docs/architecture/pdf-source-autofill.md. Member ownership and current authority required; all writes require same-origin CSRF. No inference or external effects.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own private result; download URL absent until final exact-hash confirmation"
          },
          "400": {
            "description": "Invalid or unsupported binding or request"
          },
          "403": {
            "description": "Unknown or foreign reference, role denial or missing CSRF"
          },
          "409": {
            "description": "Source mapping or output changed; prepare and review again"
          }
        }
      }
    },
    "/api/v1/forms/{id}/confirm": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "pdfConfirmOutput",
        "summary": "Confirm the exact verified output hash before issuing a PDF download",
        "security": [
          {
            "session": []
          }
        ],
        "description": "See docs/architecture/pdf-source-autofill.md. Member ownership and current authority required; all writes require same-origin CSRF. No inference or external effects.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own private result; download URL absent until final exact-hash confirmation"
          },
          "400": {
            "description": "Invalid or unsupported binding or request"
          },
          "403": {
            "description": "Unknown or foreign reference, role denial or missing CSRF"
          },
          "409": {
            "description": "Source mapping or output changed; prepare and review again"
          }
        }
      }
    },
    "/api/v1/attachments/bundles": {
      "post": {
        "operationId": "freezeAttachmentBundle",
        "summary": "Freeze exact PDF artifact hashes; never authorizes sending",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Same-origin CSRF required. Strict request keys and 16 KiB limit. Server-derived tenant and current member ownership; viewer, pause, privacy, source and membership fences apply. See docs/architecture/artifacts.md for exact per-operation fields and supported limits. Public AI and Drive writing remain unavailable.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Own snapshot or truthful validation state; drive_status=unavailable, never sent or Drive saved"
          },
          "400": {
            "description": "Invalid request"
          },
          "403": {
            "description": "Unknown or foreign id, missing CSRF or forbidden role"
          },
          "409": {
            "description": "Stale source or divergent request id; review again"
          }
        }
      }
    },
    "/api/v1/transcriptions": {
      "get": {
        "operationId": "transcriptionCapability",
        "summary": "Own local speech capability (false while activation gates are closed)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "available, native_voice=false, max_seconds=60 and max_bytes=2097152; no microphone or model starts"
          }
        }
      },
      "post": {
        "operationId": "createTranscription",
        "summary": "Explicitly consented private audio proposal, never a message send",
        "description": "Requires same-origin CSRF and voice_local_stt gates. Bounded container bytes are compressed server-side into the existing private B2 module; the sole leased scheduler transcribes on Master. Exact id/body repeats are idempotent. Unknown fields, authority/model options, unsupported codecs/locales and viewers are rejected. Audio and encrypted transcript expire after 15 minutes; physical cleanup requires the documented timer and erasure authority. The route remains disabled until those operational gates pass.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "audio",
                  "type",
                  "locale",
                  "consent"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "audio": {
                    "type": "string",
                    "contentEncoding": "base64",
                    "maxLength": 2796204
                  },
                  "type": {
                    "enum": [
                      "audio/webm",
                      "audio/ogg",
                      "audio/mp4"
                    ]
                  },
                  "locale": {
                    "enum": [
                      "pt-PT",
                      "en",
                      "es",
                      "fr",
                      "de",
                      "it",
                      "nl",
                      "pl",
                      "he",
                      "ar",
                      "zh-CN",
                      "ja",
                      "ko",
                      "ru",
                      "uk",
                      "tr"
                    ]
                  },
                  "consent": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "transcription with id/state/text(null until ready)/expires_at/native_voice=false; received is never sent"
          },
          "400": {
            "description": "Invalid consent, codec, signature, size, locale or input"
          },
          "403": {
            "description": "Origin/CSRF or membership denied"
          },
          "409": {
            "description": "Frozen input conflict or bounded hourly quota"
          },
          "503": {
            "description": "Local speech or B2 unavailable; no fallback provider"
          }
        }
      }
    },
    "/api/v1/transcriptions/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "readTranscription",
        "summary": "Own actor-scoped editable transcript; expired text is never decrypted",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "transcription with state receiving/queued/ready/failed/deleted/expired, nullable text, expiry and native_voice=false"
          },
          "403": {
            "description": "Unknown or foreign id; same response"
          }
        }
      },
      "delete": {
        "operationId": "discardTranscription",
        "summary": "Revoke pending publication, erase transcript and purge private B2 ingress",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "deleted=true; requires same-origin CSRF, works independently of local model gate"
          },
          "403": {
            "description": "Missing CSRF or unknown/foreign id"
          }
        }
      }
    },
    "/api/v1/commands": {
      "get": {
        "operationId": "listCommands",
        "summary": "Latest 30 requests owned by this membership",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "commands array; private encrypted input is decrypted only after authorization; never complete"
          }
        }
      },
      "post": {
        "operationId": "submitCommand",
        "summary": "Save a request and return its stable receipt (AI remains off)",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Exact session Origin and X-CSRF-Token required. Same actor/key/input returns the original receipt; changed input for that key returns 409. Unknown fields including tenant, plan or policy are rejected. File and voice references must resolve to ready media owned by this membership; no remote URLs. No inference, connector call or effect is dispatched. Missing crypto fails closed. Device-queued intake supplies X-Offline-Binding from the current /me response and Idempotency-Key matching body.key. A different current identity/session/authority binding returns 409 before admission.",
        "parameters": [
          {
            "in": "header",
            "name": "X-Offline-Binding",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "key",
                  "text"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9_-]{16,100}$"
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 4000
                  },
                  "files": {
                    "type": "array",
                    "maxItems": 4,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "voice_ref": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "command receipt: id, version, state, reason, input, plan (nullable), complete=false"
          },
          "400": {
            "description": "Invalid or oversized JSON body"
          },
          "403": {
            "description": "Missing CSRF, wrong origin or read-only membership"
          },
          "404": {
            "description": "Source unavailable or not owned"
          },
          "409": {
            "description": "Changed payload or invalid input; no mutation"
          }
        }
      }
    },
    "/api/v1/commands/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getCommand",
        "summary": "Read own durable receipt; expired or revoked plan stays held",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Command receipt; no effect completion claim"
          },
          "404": {
            "description": "Command unavailable or not owned"
          }
        }
      }
    },
    "/api/v1/commands/{id}/cancel": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "cancelCommand",
        "summary": "Cancel an own request using its current version",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Exact session Origin and X-CSRF-Token required. Repeated cancellation is idempotent. No effects exist in this intake path.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "version"
                ],
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Durable cancelled receipt"
          },
          "409": {
            "description": "Stale version"
          }
        }
      }
    },
    "/api/v1/agenda": {
      "get": {
        "operationId": "calendarAgenda",
        "summary": "Selected owned-calendar day projection (OC-043)",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Server-derived tenant and connection owner only. Exact IANA timezone, date-only all-day dates, recurrence instances, per-calendar check time/state/selection/revision, and coverage. Free intervals exist only with complete selected coverage, current grants and checks within five minutes. Import never approves attendance or accepts invitations. Runtime connection_available is currently false.",
        "parameters": [
          {
            "in": "query",
            "name": "date",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "in": "query",
            "name": "time_zone",
            "schema": {
              "type": "string",
              "default": "UTC"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Agenda envelope; see docs/architecture/calendar.md and shared/src/api/agenda.ts."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/calendar/selection": {
      "patch": {
        "operationId": "calendarSelection",
        "summary": "Explicitly include or exclude an owned calendar",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Exact session origin and CSRF required. Duplicate desired state is a no-op; stale revision is 409.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "selected",
                  "revision"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "selected": {
                    "type": "boolean"
                  },
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Local selection saved; does not claim provider freshness."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/connections/google/calendar/read": {
      "post": {
        "operationId": "calendarReadAvailability",
        "summary": "Calendar connection activation gate",
        "security": [
          {
            "session": []
          }
        ],
        "description": "Exact origin and CSRF required. Always 409 until official OAuth/runtime activation; no provider call.",
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/files/root": {
      "get": {
        "operationId": "driveRootStatus",
        "summary": "Own Drive availability (OC-004, OC-049)",
        "description": "Authenticated. Returns available=false and root=null until official OAuth, connector runtime and policy are activated. Existing B2 files remain independent.",
        "responses": {
          "200": {
            "description": "Truthful gated state; no provider requests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DriveRoot"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required."
          }
        }
      }
    },
    "/api/v1/files/root/ensure": {
      "post": {
        "operationId": "ensureDriveRoot",
        "summary": "Own Drive admission (gated)",
        "description": "Session, exact origin and CSRF required. No client-selected tenant, account, remote ID or success flag is accepted. No mutation is enabled.",
        "responses": {
          "401": {
            "description": "Authentication required."
          },
          "403": {
            "description": "Origin or CSRF refused."
          },
          "409": {
            "description": "drive_unavailable; no root, outbox or provider effect created."
          }
        }
      }
    },
    "/api/v1/actions": {
      "post": {
        "operationId": "createAction",
        "summary": "Effect admission (OC-022)",
        "description": "Session, same-origin and CSRF required. No product adapters/policy enabled; always unavailable in IMPL-012. No client-provided policy or success flags are accepted.",
        "responses": {
          "409": {
            "description": "effects_unavailable; no task, attempt or provider I/O created."
          }
        }
      }
    },
    "/api/v1/actions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getAction",
        "summary": "Actor-owned action and safe proof chronology",
        "responses": {
          "200": {
            "description": "Accepted is distinct from sent, delivered, read; unknown is checking.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "404": {
            "description": "Unknown, malformed or foreign action (same response)."
          }
        }
      }
    },
    "/api/v1/actions/{id}/evidence": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getActionEvidence",
        "summary": "Safe observations (no raw provider response, tokens, prompts or payload)",
        "responses": {
          "200": {
            "description": "Evidence envelope plus request_id; unavailable source is explicit.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "evidence",
                    "request_id"
                  ],
                  "properties": {
                    "evidence": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Action/$defs/event"
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/actions/{id}/cancel": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "cancelAction",
        "summary": "Cancel only before dispatch (session, same-origin, CSRF)",
        "responses": {
          "200": {
            "description": "Cancelled before provider I/O; repeat is harmless.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "409": {
            "description": "An attempted or uncertain effect cannot be cancelled as unsent."
          }
        }
      }
    },
    "/api/v1/actions/{id}/reconcile": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "reconcileAction",
        "summary": "Read-only provider lookup (session, same-origin, CSRF)",
        "responses": {
          "200": {
            "description": "Observed result; missing remote proof stays Checking. Never resends.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Action"
                }
              }
            }
          },
          "409": {
            "description": "In flight, not started or provider unavailable."
          }
        }
      }
    },
    "/api/v1/tasks/{id}/activity": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getEffectTaskActivity",
        "summary": "Transport task proof (effect_tasks; general task ledger remains IMPL-016/029)",
        "responses": {
          "200": {
            "description": "Activity envelope plus request_id; only the actor's own linked action.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "activity",
                    "request_id"
                  ],
                  "properties": {
                    "activity": {
                      "$ref": "#/components/schemas/Action/$defs/action"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mcp": {
      "post": {
        "operationId": "mcpJsonRpc",
        "summary": "Model Context Protocol endpoint (Streamable HTTP, JSON-RPC 2.0)",
        "description": "Also served at /mcp. Stateless, read-only, no SSE and no batches; protocol versions 2025-11-25, 2025-06-18 and 2025-03-26. initialize, ping, tools/list and the get_service_info tool are public. get_account, get_today and list_tasks read only the account of the session cookie sent with the request (use the app host) and answer HTTP 401 with JSON-RPC error -32001 without it. A browser Origin other than the site/app origins is refused with 403. Notifications answer 202 with no body.",
        "security": [
          {},
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "jsonrpc",
                  "method"
                ],
                "properties": {
                  "jsonrpc": {
                    "const": "2.0"
                  },
                  "id": {
                    "type": [
                      "string",
                      "integer"
                    ]
                  },
                  "method": {
                    "type": "string",
                    "enum": [
                      "initialize",
                      "ping",
                      "tools/list",
                      "tools/call",
                      "notifications/initialized"
                    ]
                  },
                  "params": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC result or error object.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "202": {
            "description": "Notification accepted (no body)."
          },
          "400": {
            "description": "Parse error, invalid request or unsupported MCP-Protocol-Version.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Account tool called without a valid session (JSON-RPC error -32001).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "415": {
            "description": "Content-Type is not application/json.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "mcpNoStream",
        "summary": "No SSE stream is offered",
        "responses": {
          "405": {
            "description": "Only POST is accepted (JSON body).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/mcp/discovery": {
      "get": {
        "operationId": "mcpDiscovery",
        "summary": "MCP discovery card (also /.well-known/mcp.json)",
        "responses": {
          "200": {
            "description": "Server identity, transport endpoint, protocol versions, authentication and tools.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "protocolVersion",
                    "serverInfo",
                    "transport",
                    "authentication",
                    "tools"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/revision": {
      "get": {
        "operationId": "getRevision",
        "summary": "Live deployed revision",
        "responses": {
          "200": {
            "description": "Deployed revision of this environment.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "const": "no-store"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Revision"
                }
              }
            }
          },
          "503": {
            "description": "Revision unknown (never invented).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/healthz": {
      "get": {
        "operationId": "getHealth",
        "summary": "Public health without private or dependency detail",
        "responses": {
          "200": {
            "description": "Release healthy; unconfigured subsystems reported as not_configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Healthz"
                }
              }
            }
          },
          "503": {
            "description": "Release facts unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Healthz"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/magic-links": {
      "post": {
        "operationId": "requestMagicLink",
        "summary": "E-mail a one-use sign-in link (OC-001)",
        "description": "Public (no session). Alias: POST /api/auth/magic-link. Origin must be exactly one of this environment's origins (APP_URL and its app./apex sibling, from configuration) AND name the request's own Host, so a forged Host can never redirect links. Content-Type application/json (max 1024 bytes, unknown fields rejected). Rate limited per e-mail (3) and per client network (10; IPv6 /64) per 15 minutes; answers do not depend on whether an account exists. 202 means the SMTP server answered 250 to the end of DATA (accepted for delivery), never \"delivered\". Sets the host-only __Host-oc_signin nonce cookie (HttpOnly, 15 minutes): the link works only in this browser. The link is <origin>/auth/link?lang=xx#<token> (token in the fragment only); the response never contains it, the address or any setting. Explicit consent (SLICE-A-SITE): terms_version and privacy_version are required (400 consent_required) and must be current (409 terms_changed); the account stores them with the acceptance time.",
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MagicLinkRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted by the SMTP server.",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "__Host-oc_signin=<nonce>; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=900"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MagicLinkAccepted"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "405": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "description": "Too many requests for this address or network (Retry-After 900).",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "not_configured (mail/database settings absent or invalid), unavailable (database) or mail_not_accepted (the SMTP server refused or failed; nothing was sent).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/magic-links/consume": {
      "post": {
        "operationId": "consumeMagicLink",
        "summary": "Sign in with the link (OC-001/OC-002)",
        "description": "POST only (GET/HEAD are 405: mail scanners consume nothing). Sent by the app page the link opened, with the exact origin the link was requested from and the same browser (__Host-oc_signin). One transaction consumes the link exactly once (parallel consumes: one session), creates the personal workspace on first use, and issues a NEW session (any session this browser presented is revoked: rotation). Unknown, malformed, expired, used, failed-delivery, other-host links and inactive accounts all give the same 400 link_invalid; a live link in another browser gives 403 other_browser and stays usable in the right browser.",
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MagicLinkConsume"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in.",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "__Host-oc_session (HttpOnly, Lax), __Host-oc_csrf (Strict, script-readable), clears __Host-oc_signin"
              },
              "Clear-Site-Data": {
                "schema": {
                  "const": "\"cache\""
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SignedIn"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "405": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "description": "not_configured (database, mail or sign-in keys absent; nothing consumed) or unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/apple/notifications": {
      "post": {
        "operationId": "appleServerNotification",
        "summary": "Receive verified Apple account changes",
        "security": [],
        "description": "Server-to-server JWS authentication only; no cookies, browser session, Origin, CSRF or redirect. JSON object body, at most 65536 actual bytes; payload is a compact RS256 JWS verified using cached Apple JWKS (unknown kid refetch throttled to once per minute). Exact issuer https://appleid.apple.com; aud must be the string fun.openclone.app or fun.openclone.web, never an array. Integer iat is required, within [now-604800,now+60]. exp is optional; when present it must be an integer at least now-60. No nonce or top-level sub required. events is an object or JSON object string with bounded type/sub and nonnegative integer event_time (integer or digit string within signed 64-bit range). Optional contact claims never change a login address. 300 requests per 600-second window per hashed client network. Receipt and account effects commit atomically; replay repeats no effects. Infrastructure failures are retryable and never acknowledged as replay. Apple unavailable returns 404.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "payload"
                ],
                "properties": {
                  "payload": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Handled, unknown subject/type, or already processed; no authentication cookies.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "outcome",
                    "request_id"
                  ],
                  "properties": {
                    "outcome": {
                      "enum": [
                        "updated",
                        "unlinked",
                        "kept",
                        "erased",
                        "unknown_sub",
                        "unknown_type",
                        "replay"
                      ]
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Generic invalid notification; no validation details."
          },
          "404": {
            "description": "Apple not configured or unavailable."
          },
          "405": {
            "description": "POST required.",
            "headers": {
              "Allow": {
                "schema": {
                  "type": "string",
                  "const": "POST"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 64 KiB; enforced before JSON parsing."
          },
          "429": {
            "description": "Dedicated hashed request limit reached.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "const": 600
                }
              }
            }
          },
          "503": {
            "description": "Retryable JWKS, database, locking or application failure; effects rolled back.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer",
                  "const": 30
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/apple/start": {
      "post": {
        "operationId": "startAppleSignIn",
        "summary": "Start Sign in with Apple or explicitly link a signed-in account",
        "description": "Hidden/404 without complete APP_APPLE_* configuration. Only the four registered HTTPS hosts (loopback permitted by the dev mock). Exact Origin required. Sign-in requires consent; purpose link requires session, CSRF and recent authentication. State is one-use, host/browser bound, expires in 10 minutes; nonce is SHA-256. Returns form_post authorize URL with name email.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "purpose": {
                    "enum": [
                      "signin",
                      "link"
                    ]
                  },
                  "terms_version": {
                    "type": "string"
                  },
                  "privacy_version": {
                    "type": "string"
                  },
                  "lang": {
                    "type": "string"
                  },
                  "time_zone": {
                    "type": "string"
                  },
                  "return_to": {
                    "type": "string",
                    "maxLength": 200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Navigate to authorize_url; sets the Lax browser-binding cookie.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleStart"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/apple/callback": {
      "post": {
        "operationId": "appleSignInCallback",
        "summary": "Cross-site Apple form_post handoff",
        "description": "Only this route exempts Origin/CSRF. Validates and consumes host-bound state, seals code and optional first-authorization name. Creates no session and sets no cookie. Redirects to complete with a one-use reference (5 minutes). Errors return to /?signin_error=apple.",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "state": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "user": {
                    "type": "string",
                    "description": "First-authorization JSON name; email ignored"
                  },
                  "error": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "303": {
            "description": "Same-site completion or friendly sign-in failure.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "405": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/apple/complete": {
      "get": {
        "operationId": "completeAppleSignIn",
        "summary": "Verify Lax browser cookie, exchange code and establish session",
        "description": "One-use reference and browser/host binding checked before token exchange. ES256 client secret, RS256 ID token via cached JWKS, issuer/audience/time/nonce/sub verification. Subject first; verified non-relay email may join an existing account. Relay never auto-links. Purpose link checks the same signed-in user. Session cookies remain Secure HttpOnly SameSite=Lax.",
        "parameters": [
          {
            "name": "t",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "Session established, settings link result, or friendly sign-in error.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "405": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/me/apple": {
      "delete": {
        "operationId": "unlinkApple",
        "summary": "Remove Apple while another sign-in method remains",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Unlinked (also if already absent)."
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/google/start": {
      "post": {
        "operationId": "startGoogleSignIn",
        "summary": "Start \"Continue with Google\" (SLICE-A-SITE)",
        "description": "Exists only when GOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET are configured for this environment and e-mail sign-in is configured (healthz checks.google = configured); otherwise 404 and the app shows no Google button. Same origin, body-size and consent rules as the magic-link request. Stores a one-use state (10 minutes) bound to this browser (__Host-oc_signin) and host, with the PKCE verifier and OIDC nonce sealed; returns Google's authorize URL (scopes openid email). Shares the per-network rate limit with magic links.",
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "terms_version",
                  "privacy_version"
                ],
                "properties": {
                  "terms_version": {
                    "type": "string",
                    "pattern": "^[0-9]{1,8}$"
                  },
                  "privacy_version": {
                    "type": "string",
                    "pattern": "^[0-9]{1,8}$"
                  },
                  "lang": {
                    "type": "string"
                  },
                  "time_zone": {
                    "type": "string"
                  },
                  "return_to": {
                    "type": "string",
                    "maxLength": 200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Redirect the browser to authorize_url.",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "__Host-oc_signin=<nonce>; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=900"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleStart"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/google/callback": {
      "get": {
        "operationId": "googleSignInCallback",
        "summary": "Google redirects the browser here (SLICE-A-SITE)",
        "description": "Register https://<host>/api/v1/auth/google/callback for the app and site hosts of the environment in the Google OAuth client. Consumes the state (one use, same browser and host), exchanges the code over verified TLS with the client secret and PKCE verifier, checks the ID token (iss, aud/azp, exp/iat, nonce, email_verified) and signs in the verified address through the same keyed login digest as the e-mail link (one person, one account), creating the account with the consent the state carries. Success: 303 to the app path the sign-in started from (default /) with new session cookies. Any failure: 303 to /?signin_error=google (or other_browser), nothing signed in.",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "error",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "303": {
            "description": "Back to the app (signed in, or with signin_error).",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              },
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "On success: __Host-oc_session, __Host-oc_csrf; clears __Host-oc_signin"
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "405": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/methods": {
      "get": {
        "operationId": "signInMethods",
        "summary": "Sign-in options this server offers now (OC-LOGIN-WHATSAPP)",
        "description": "Public. email = e-mail magic link configured; whatsapp = WhatsApp login (a WhatsApp message only; never any other message channel) enabled: APP_WHATSAPP_PROVIDER=group with valid WA_GATEWAY_* and the group WhatsApp gateway's health answering (cached 60 s), or the dev simulator for a request carrying the dev APP_E2E_KEY; google = GOOGLE_CLIENT_ID configured. A false option is hidden in the app, never shown disabled.",
        "responses": {
          "200": {
            "description": "Available options.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "email",
                    "whatsapp",
                    "google",
                    "apple",
                    "request_id"
                  ],
                  "properties": {
                    "review_login": {
                      "type": "boolean",
                      "enum": [
                        true
                      ],
                      "description": "Present only when the App Review credential is configured"
                    },
                    "email": {
                      "type": "boolean"
                    },
                    "whatsapp": {
                      "type": "boolean"
                    },
                    "google": {
                      "type": "boolean"
                    },
                    "apple": {
                      "type": "boolean"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/auth/whatsapp/start": {
      "post": {
        "operationId": "startWhatsAppLogin",
        "summary": "Start an inbound WhatsApp login (OC-LOGIN-WHATSAPP)",
        "description": "Public for sign-in/sign-up (same flow); purpose \"link\" needs a session (Origin + X-CSRF-Token) created in the last 10 minutes (403 reauth_required). Origin must be an exact environment origin naming the request's Host; JSON max 1024 bytes, unknown fields rejected. Sign-in requires the consent exactly like the magic link (400 consent_required / 409 terms_changed). The server asks the group WhatsApp gateway for a short code and a wa_link that opens WhatsApp with a prefilled message to the group number; the person sends it from their own WhatsApp (openclone never sends WhatsApp messages). Same answer whether or not an account exists. Rate limits: per client network 10 / 15 min (IPv6 /64), per browser nonce 5 / 15 min, per typed number 5 / 10 min; a gateway 429 is a 429 with its Retry-After. challenge_id is openclone's own random id (never the gateway's request id, which stays server-side, sealed). Example gateway base URL in configuration docs only: https://gateway.example.test/wa-gateway.",
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "lang": {
                    "type": "string"
                  },
                  "terms_version": {
                    "type": "string",
                    "pattern": "^[0-9]{1,8}$"
                  },
                  "privacy_version": {
                    "type": "string",
                    "pattern": "^[0-9]{1,8}$"
                  },
                  "return_to": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "phone": {
                    "type": "string",
                    "maxLength": 32,
                    "description": "Optional number the WhatsApp sender must have (normalised to E.164; PT must be a mobile)"
                  },
                  "country": {
                    "type": "string",
                    "pattern": "^[1-9][0-9]{0,2}$",
                    "description": "Calling code from the country picker (default 351)"
                  },
                  "time_zone": {
                    "type": "string"
                  },
                  "purpose": {
                    "enum": [
                      "signin",
                      "link"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Show the button (mobile) or QR (desktop) of wa_link and the fallback line \"send {code} to {wa_number}\".",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "__Host-oc_signin=<nonce>; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=900"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "challenge_id",
                    "wa_link",
                    "code",
                    "wa_number",
                    "expires_at",
                    "ttl_seconds",
                    "request_id"
                  ],
                  "properties": {
                    "challenge_id": {
                      "type": "string",
                      "pattern": "^[A-Za-z0-9_-]{43}$"
                    },
                    "wa_link": {
                      "type": "string",
                      "format": "uri"
                    },
                    "code": {
                      "type": "string",
                      "pattern": "^[ACDEFGHJKMNPQRTUVWXY34679]{6}$"
                    },
                    "wa_number": {
                      "type": "string",
                      "pattern": "^\\+[1-9][0-9]{7,14}$"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "ttl_seconds": {
                      "type": "integer"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/whatsapp/{challenge_id}/status": {
      "get": {
        "operationId": "whatsAppLoginStatus",
        "summary": "Poll an inbound WhatsApp login (every 2 s while the page is visible)",
        "description": "Bound to the browser that started it (__Host-oc_signin) and to the host. Asks the group WhatsApp gateway; its one-shot 'verified' is persisted (sealed) before any work, then ONE transaction creates the account (consent, class real with a founder number by the founders rules; the dev simulator creates class test without one) or uses the account of that number, and issues a new session (auth method whatsapp_code; never owner-capable). For purpose link the number joins the signed-in account. 1 call per second per challenge, 120 per minute per network. Every unusable challenge (unknown, other browser/host, used) is the same 400 invalid_or_expired.",
        "parameters": [
          {
            "name": "challenge_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            }
          },
          {
            "name": "lang",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tz",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{status: pending|expired, expires_at}; {status: linked, expires_at}; or {status: signed_in, created, return_to, csrf_token} with new session cookies (__Host-oc_session, __Host-oc_csrf; the sign-in nonce is cleared)."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/whatsapp/{challenge_id}/check": {
      "post": {
        "operationId": "whatsAppLoginCheck",
        "summary": "The \"Já enviei\" button - same as status, through the gateway's verify endpoint",
        "parameters": [
          {
            "name": "challenge_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            }
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Same as GET .../status."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/auth/e2e-whatsapp-inbound": {
      "post": {
        "operationId": "e2eWhatsAppInbound",
        "summary": "DEV ONLY Playwright hook (the person \"sends\" the code to the dev simulator)",
        "description": "Exists only on a dev release with APP_ENV=dev and a valid X-E2E-Key (APP_E2E_KEY), for a dev-simulator challenge of this browser and a synthetic e2e number (+351 91 000 0xxx); anything else is the plain 404 of an unknown route.",
        "parameters": [
          {
            "name": "X-E2E-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "challenge_id",
                  "phone"
                ],
                "properties": {
                  "challenge_id": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{status: inbound_recorded}"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/me/phone": {
      "delete": {
        "operationId": "unlinkWhatsApp",
        "summary": "Remove the WhatsApp number from the signed-in account (only while the e-mail remains)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{status: unlinked}"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "last_method: the number is the only way into this account"
          }
        }
      }
    },
    "/api/v1/me": {
      "get": {
        "operationId": "getMe",
        "summary": "The signed-in identity (own address, account defaults, current workspace)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Own account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/auth/logout": {
      "post": {
        "operationId": "logout",
        "summary": "End this session",
        "description": "Exact session origin + X-CSRF-Token. Revokes the session, clears its cookies and the HTTP cache of this host (Clear-Site-Data \"cache\"); the next request with the old cookie is 401.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Signed out.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "request_id"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "status": {
                      "const": "signed_out"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/sessions": {
      "get": {
        "operationId": "listSessions",
        "summary": "Active devices of the signed-in identity (OC-002)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Live sessions, newest use first; no IP address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Sessions"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "delete": {
        "operationId": "revokeOtherSessions",
        "summary": "Sign out every other device (this one stays signed in)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Number of sessions ended.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "signed_out",
                    "request_id"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "signed_out": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/sessions/idle-policy": {
      "get": {
        "operationId": "getIdlePolicy",
        "summary": "Idle sign-out threshold of this membership (days; null = never)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Threshold; a member who never chose reads the default (90).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionsIdlePolicy"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "patch": {
        "operationId": "setIdlePolicy",
        "summary": "Store the member's own idle sign-out threshold (30, 60, 90 or null = never)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "idle_days"
                ],
                "additionalProperties": false,
                "properties": {
                  "idle_days": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "enum": [
                      30,
                      60,
                      90,
                      null
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionsIdlePolicy"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/sessions/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "X-CSRF-Token",
          "in": "header",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "delete": {
        "operationId": "revokeSession",
        "summary": "Sign out one device (a lost phone); current = this device (cookies cleared)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Signed out.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "current",
                    "request_id"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "status": {
                      "const": "signed_out"
                    },
                    "current": {
                      "type": "boolean"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "description": "Unknown, already ended or another identity's session (same answer).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "renameSession",
        "summary": "Rename a device (editable label, 1-64 characters)",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "label"
                ],
                "additionalProperties": false,
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Renamed.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "session",
                    "request_id"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "session": {
                      "type": "object",
                      "required": [
                        "id",
                        "label"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "label": {
                          "type": "string"
                        }
                      }
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/workspaces": {
      "get": {
        "operationId": "listWorkspaces",
        "summary": "Workspaces of the signed-in identity (OC-003)",
        "description": "Active memberships of the session's identity, resolved by AuthRepository. Personal workspace first. Client tenant headers are ignored.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Workspaces; `current` marks the session's workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Workspaces"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/switch": {
      "post": {
        "operationId": "switchWorkspace",
        "summary": "Switch the session to another workspace with an active membership (OC-003)",
        "description": "Requires the exact same-origin Origin header and X-CSRF-Token. The server verifies an active membership, revokes the current session and sets a new host-only cookie; the old cookie stops working (duplicate submits get 401). Clear-Site-Data \"cache\" drops caches of the previous context. Not-a-member, unknown and reserved ids give the same 404.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "workspace_id"
                ],
                "properties": {
                  "workspace_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Switched; new session cookie and CSRF token.",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "__Host-oc_session=...; Path=/; Secure; HttpOnly; SameSite=Lax"
              },
              "Clear-Site-Data": {
                "schema": {
                  "const": "\"cache\""
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceSwitch"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/preferences": {
      "get": {
        "operationId": "getPreferences",
        "summary": "The current member's language, format locale and time zone (OC-074)",
        "description": "Keyed by the session's server-derived tenant and membership; no client field or header selects another member. version 0 and null fields mean nothing was chosen yet.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current preferences.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preferences"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "patch": {
        "operationId": "updatePreferences",
        "summary": "Save the current member's language, format locale and/or IANA time zone (OC-074)",
        "description": "Same-origin Origin and X-CSRF-Token required. Send only the fields to change plus the version last read. Repeating an already-applied change answers 200 unchanged (duplicate submit); a stale version answers 409 and changes nothing. Locales are exact supported codes; time zones IANA names; null clears. Errors never echo submitted values.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "version"
                ],
                "minProperties": 2,
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "ui_locale": {
                    "enum": [
                      null,
                      "pt-PT",
                      "en",
                      "es",
                      "fr",
                      "de",
                      "it",
                      "nl",
                      "pl",
                      "he",
                      "ar",
                      "zh-CN",
                      "ja",
                      "ko",
                      "ru",
                      "uk",
                      "tr"
                    ]
                  },
                  "format_locale": {
                    "enum": [
                      null,
                      "pt-PT",
                      "en",
                      "es",
                      "fr",
                      "de",
                      "it",
                      "nl",
                      "pl",
                      "he",
                      "ar",
                      "zh-CN",
                      "ja",
                      "ko",
                      "ru",
                      "uk",
                      "tr"
                    ]
                  },
                  "time_zone": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 64,
                    "description": "IANA time zone identifier"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved (or already applied).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preferences"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/today": {
      "get": {
        "operationId": "getToday",
        "summary": "At most three needs-you cards, the count of the rest and source coverage (OC-005)",
        "description": "Deterministic ranking (explicit approvals, deadlines, recoverable connection issues, ordinary review; then due time, then source key), one card per underlying need. view=all lists every visible need. quiet (All set) is true only when every released source is connected and current and nothing is pending. Codes and opaque ids only; the UI renders them through the catalogs.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "view",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "all"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Today for the current member.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Today"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/today/{source}/hide": {
      "parameters": [
        {
          "name": "source",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-z_]{1,24}\\.[0-9a-f-]{36}$"
          }
        }
      ],
      "post": {
        "operationId": "hideTodayCard",
        "summary": "Hide one card at its current revision (OC-005)",
        "description": "Hiding never cancels the underlying need; a newer revision of the source shows the card again. Approvals and deadlines cannot be hidden (409). A revision other than the current one answers 409 (the client refreshes); a card that is not the member's own current card answers 404. Repeating the same hide answers 200.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "revision"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Hidden; the refreshed Today (status hidden, today)."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/activity": {
      "get": {
        "operationId": "listActivity",
        "summary": "The member's own recent recorded events (OC-005)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Newest first, at most 20, codes and times only.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Activity"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/sources": {
      "get": {
        "operationId": "listSources",
        "summary": "Source coverage for the shell containers (OC-005, OC-075)",
        "description": "Every source the shell knows with the member's own connection state. A source whose connector is not released in this environment is unavailable, never connected. connected always carries checked_at.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Sources.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Sources"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/files": {
      "get": {
        "operationId": "listFiles",
        "summary": "Own files with fresh short-lived signed URLs (IMPL-B2-STORAGE)",
        "description": "Newest 100 ready files of the current workspace (images: AVIF + WebP widths; videos: MP4 renditions + WebP poster; documents: the original) with presigned GET URLs on the private bucket (X-Amz-Expires <= TTL, default 600 s, max 3600 s; refresh before urls_expire_at), plus uploads still processing or failed. available=false when storage is not configured here (nothing faked).",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Files and uploads.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Files"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/invoices/batches": {
      "get": {
        "operationId": "listInvoiceBatches",
        "summary": "Latest 20 actor-owned local review batches",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "batches[{id}]; source access is rechecked when opened."
          }
        }
      },
      "post": {
        "operationId": "createInvoiceBatch",
        "summary": "Reuse completed extraction evidence for selected captures",
        "description": "Requires Origin and X-CSRF-Token. At most 20 selected IDs (repeats deduplicated), 80 physical candidates and 500 comparison reviews. Missing evidence stays excluded. Never downloads or extracts. The id is the actor-scoped idempotency key; a changed selection refuses.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "capture_ids"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "capture_ids": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 20,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "batch envelope; shared/schemas/invoices/batch-v1.json."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/invoices/batches/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getInvoiceBatch",
        "summary": "Resume persisted progress with current evidence and duplicate status",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "batch envelope; shared/schemas/invoices/batch-v1.json."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/invoices/batches/{id}/refresh": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refreshInvoiceBatch",
        "summary": "Retry completed evidence without replacing invoice corrections",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current batch envelope. Never extracts or downloads originals."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/invoices/batches/{id}/confirm": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "confirmInvoiceBatch",
        "summary": "Atomically save the exact reviewed clear subset in the local register",
        "description": "Origin and CSRF required. No payments, filing, messages or provider effects. Revalidates sources, extraction and invoice revisions, duplicates, active areas and authority. Conflicts commit nothing; reload to reconcile uncertain responses. At most 80 confirmation attempts per batch.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "id",
                  "reviewed",
                  "items"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reviewed": {
                    "const": true
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 80,
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "invoice_id",
                        "token",
                        "context_id",
                        "year"
                      ],
                      "properties": {
                        "invoice_id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "token": {
                          "type": "string",
                          "pattern": "^[a-f0-9]{64}$"
                        },
                        "context_id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "year": {
                          "type": "integer",
                          "minimum": 1900,
                          "maximum": 2199
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current persisted batch plus confirmed_ids for this request."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "Stale selection, exception, duplicate, mismatched idempotency payload or busy register. Reload and review; no partial commit."
          }
        }
      }
    },
    "/api/v1/invoices/batches/{id}/resolve": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "resolveInvoiceBatchDuplicate",
        "summary": "Choose an existing duplicate record without merging or confirming either source",
        "description": "Requires Origin and CSRF. Revalidates source token, target revision, source availability and duplicate evidence. Durable encrypted resolution history; changes invalidate the choice. An unresolved review may become clear only after all its duplicates have been explicitly linked to it.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "invoice_id",
                  "token",
                  "target_id",
                  "target_revision",
                  "reviewed"
                ],
                "properties": {
                  "invoice_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "token": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  },
                  "target_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "target_revision": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "reviewed": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Current batch; linked sources excluded from totals. No invoice deleted, merged or confirmed."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/invoices/{id}/refresh": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "refreshInvoiceEvidence",
        "summary": "Explicit individual re-review of changed evidence",
        "description": "Retains old evidence and corrections; new conflicts remain conflicts. Refreshed sources require individual confirmation, never become automatically clear for bulk confirmation.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "revision"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Invoice envelope with source_history and incremented revision."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/invoices/capture": {
      "post": {
        "operationId": "captureInvoice",
        "summary": "Review one physical page of an owned B2 capture",
        "description": "Bounded local reading or manual entry; no model, payment, tax submission or Drive filing. Requires Origin and X-CSRF-Token.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "capture_id",
                  "manifest_page",
                  "page"
                ],
                "properties": {
                  "capture_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "manifest_page": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 20
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "invoice envelope; shared/schemas/invoices/review-v1.json. Replays reuse the same review."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/invoices/{id}": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getInvoice",
        "summary": "Current actor-owned source evidence and corrections",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "invoice envelope; payment_status=unknown, tax_status=unverified, drive_status=unavailable."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "correctInvoice",
        "summary": "Correct an unconfirmed invoice using its exact revision",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "revision",
                  "fields"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "fields": {
                    "type": "object",
                    "minProperties": 1,
                    "propertyNames": {
                      "enum": [
                        "issuer",
                        "buyer",
                        "issuer_tax_id",
                        "buyer_tax_id",
                        "reference",
                        "atcud",
                        "kind",
                        "amount",
                        "net",
                        "tax",
                        "vat",
                        "currency",
                        "date",
                        "due_date"
                      ]
                    },
                    "additionalProperties": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 160
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated review; original evidence retained and explicit correction history appended."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "Stale revision, correction limit or immutable confirmed record."
          }
        }
      }
    },
    "/api/v1/invoices/{id}/confirm": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "confirmInvoiceRegister",
        "summary": "Confirm the exact local register record, year and area",
        "description": "Current authority, review and totals required; duplicate merchant references cannot count twice. Confirmation never means paid, tax accepted or Drive filed.",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "revision",
                  "context_id",
                  "year",
                  "reviewed"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "context_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "year": {
                    "type": "integer",
                    "minimum": 1900,
                    "maximum": 2199
                  },
                  "reviewed": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Confirmed local register entry, including same-request replay; Drive unavailable."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "Duplicate invoice, stale revision or unresolved fields/totals; no confirmation."
          }
        }
      }
    },
    "/api/v1/expenses": {
      "get": {
        "operationId": "confirmedInvoiceTotals",
        "summary": "Confirmed records and exact totals by chosen year, area and original currency",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "records[], totals[{year,context_id,currency,amount}], complete, omitted, drive_status=unavailable. At most 200 accessible confirmed records; omissions/truncation are disclosed. No conversion or fabricated exchange rates."
          }
        }
      }
    },
    "/api/v1/captures": {
      "get": {
        "operationId": "listCaptures",
        "summary": "Latest 20 actor-owned capture manifests; never includes stored URLs",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "captures[] with ordered original and optional derivative upload states; filed=false and extraction=unavailable."
          }
        }
      },
      "post": {
        "operationId": "createCapture",
        "summary": "Create or replay an immutable ordered manifest",
        "description": "JSON {id,kind,pages:[{upload_id,derivative_id?}]}. kind=scan|document|invoice, 1..10 pages, total originals plus derivatives <=50 MiB. IDs refer only to the current actor's tenant-scoped uploads. Replays with different contents are 409. Requires exact Origin and X-CSRF-Token.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "capture: id,kind,state=draft|ready|failed,confirmed,filed=false,extraction=unavailable,pages[]."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/captures/{id}/fields": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "captureFields",
        "summary": "Own encrypted source-linked fields, or explicit unknowns",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "extraction envelope; shared/schemas/extraction/review-v1.json; model_state=held."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "correctCaptureFields",
        "summary": "Save user corrections with an exact current revision",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "revision",
                  "fields"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "fields": {
                    "type": "object",
                    "minProperties": 1,
                    "propertyNames": {
                      "enum": [
                        "amount",
                        "currency",
                        "date",
                        "due_date",
                        "iban",
                        "reference",
                        "issuer"
                      ]
                    },
                    "additionalProperties": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "maxLength": 160
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Persisted extraction envelope with source evidence and user correction history; no approval or filing."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "Stale revision or source not ready; no overwrite."
          }
        }
      }
    },
    "/api/v1/captures/{id}/review": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "reviewCaptureFields",
        "summary": "Explicitly review an exact current extraction revision for private PDF reuse",
        "security": [
          {
            "session": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "revision",
                  "reviewed"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "reviewed": {
                    "const": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reviewed extraction envelope; subsequent edits invalidate review"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/captures/{id}/extract": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "extractCapture",
        "summary": "Bounded local text/OCR/QR reading; public subscription inference held",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Persisted review fields; repeated calls retain existing corrections. Unavailable parsing preserves manual entry."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/documents/{id}/extract": {
      "parameters": [
        {
          "in": "path",
          "name": "id",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "extractDocumentCapture",
        "summary": "Alias for capture extraction; id currently identifies a capture manifest",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Same extraction envelope as POST /api/v1/captures/{id}/extract."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/captures/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getCapture",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Ordered upload states; ready means received privately, never filed in Drive."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "operationId": "deleteCapture",
        "description": "Requires Origin and CSRF. Hides the manifest; received files remain in Files until explicitly deleted.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "status=deleted"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/captures/{id}/confirm": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "confirmCapture",
        "description": "Requires Origin and CSRF. Verifies each ingress size, queues safe processing; repeat is idempotent. Missing ingress returns 409 and preserves received pages.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "202": {
            "description": "Capture state before processing; GET again for the verified result."
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/files/uploads": {
      "post": {
        "operationId": "createUpload",
        "summary": "Presigned PUT for one browser upload (IMPL-B2-STORAGE)",
        "description": "Body {\"name\", \"type\", \"size\", \"id\"?}. Optional id deduplicates retries within this tenant; changed metadata returns 409. Reissuing an unconfirmed upload renews its signed PUT; put is null after confirmation. The key is users/<workspace uuid>/incoming/<upload uuid>, derived from the session only; the signature binds Content-Type and the exact Content-Length (600 s). Limits: image 30 MiB, video 200 MiB, document 25 MiB. 415 unsupported_type, 413 too_large, 429 too_many (20 open uploads per hour), 503 encoder_missing (no AVIF+WebP / ffmpeg on this host) or storage_not_configured (details.keys = setting names).",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "type",
                  "size"
                ],
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "type": {
                    "type": "string"
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Upload recorded; PUT the bytes to put.url with put.headers.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadIssued"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/files/uploads/{id}": {
      "get": {
        "operationId": "getUpload",
        "summary": "State of one own upload (issued, uploaded, processing, ready, failed, expired)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Upload state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Not an upload of this workspace (same answer for unknown and malformed ids).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/files/uploads/{id}/complete": {
      "post": {
        "operationId": "completeUpload",
        "summary": "The browser finished its PUT; queue the media job",
        "description": "The incoming object must exist with exactly the declared size (else 409 not_uploaded / size_mismatch, and a wrong object is deleted). 202 queued: the job runs after the response (and in worker/media-worker.php); poll the upload. Repeating the call answers 200 with the current state and queues nothing.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Already confirmed (current state).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "202": {
            "description": "Queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/files/uploads/{id}/retry": {
      "post": {
        "operationId": "retryUpload",
        "summary": "Queue a failed upload again when the failure was retryable and its incoming object still exists",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/files/{id}": {
      "get": {
        "operationId": "getFile",
        "summary": "One own file with fresh signed URLs",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "description": "Not a file of this workspace (same answer for unknown, foreign and malformed ids).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteFile",
        "summary": "Delete the file and every stored variant (objects shared with another own file stay until its last file goes)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "request_id"
                  ],
                  "properties": {
                    "status": {
                      "const": "deleted"
                    },
                    "request_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/contexts": {
      "get": {
        "operationId": "listContexts",
        "summary": "Active areas of the current workspace (OC-009)",
        "description": "The default area is created on first read (personal, or household for a household workspace) and has name null. No business or fiscal area is ever seeded. Viewers see the list without creating anything.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Areas, default first.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contexts"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "post": {
        "operationId": "createContext",
        "summary": "Add a named area (OC-009)",
        "description": "Name 1-60 characters, sealed with the tenant key. Optional Idempotency-Key (UUID): a repeated key in the same workspace answers 200 with the first area instead of a second row. 409 at 50 active areas.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "kind",
                  "name"
                ],
                "properties": {
                  "kind": {
                    "enum": [
                      "personal",
                      "household",
                      "business",
                      "other"
                    ]
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Replay of the same Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Context"
                }
              }
            }
          },
          "201": {
            "description": "Created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Context"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/jobs/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getJob",
        "summary": "One durable job of the signed-in member (OC-070)",
        "description": "Truthful state (waiting, running, held, needs_you, done, cancelled, failed) with a reason code. eta is present only when the lane has enough recent observed waits and the registered capability is available; otherwise null. lower_seconds/upper_seconds are measured wait bands, never a promised completion time. Unknown, malformed, other members' and other workspaces' ids all answer the same 404.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The job.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/jobs/{id}/cancel": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "operationId": "cancelJob",
        "summary": "Cancel one of the member's jobs (OC-070)",
        "description": "Waiting, held or blocked jobs are cancelled at once. A running job keeps status running with cancel \"requested\" until its worker stops (never reported cancelled before it is). 409 when an external effect may already have happened (reason outcome_unknown): reconciliation decides. Repeating a cancel is 200.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The job after the request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/queue/status": {
      "get": {
        "operationId": "getQueueStatus",
        "summary": "The member's unfinished jobs per lane and up to 20 own job views, with held reasons and measured ETA bands or null (OC-070)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Queue status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QueueStatus"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/contexts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "getContext",
        "summary": "One area of the current workspace (archived included) (OC-009)",
        "description": "Unknown, malformed and other workspaces' ids all answer the same 404.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The area.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Context"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "patch": {
        "operationId": "updateContext",
        "summary": "Rename or archive an area at the version last read (OC-009)",
        "description": "Archived areas leave lists and search but are never deleted, so nothing linked to them is orphaned. The default area cannot be renamed or archived (409). Stale version 409; repeating an applied change 200.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "version"
                ],
                "minProperties": 2,
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 60
                  },
                  "archived": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The area.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Context"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/onboarding": {
      "get": {
        "operationId": "getFirstValue",
        "summary": "Persisted first task and held Drive/inference state (OC-004)",
        "description": "No client completion flags. Task creation uses the existing idempotent tasks endpoint. No provider work is started here.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Server-derived progress.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "onboarding",
                    "request_id"
                  ],
                  "properties": {
                    "request_id": {
                      "type": "string"
                    },
                    "onboarding": {
                      "type": "object",
                      "required": [
                        "first_value",
                        "storage",
                        "inference",
                        "next"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "first_value": {
                          "type": "boolean"
                        },
                        "storage": {
                          "const": "runtime_not_activated"
                        },
                        "inference": {
                          "const": "held"
                        },
                        "next": {
                          "enum": [
                            "task",
                            "today"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/search": {
      "post": {
        "operationId": "search",
        "summary": "Lexical search of the workspace's own records (OC-006)",
        "description": "The query travels only in the body (never a URL), is never stored or logged and is not echoed in errors. Same-origin Origin and X-CSRF-Token required. Searches current authorized tasks and areas. Unintegrated indexes are always listed in not_searched. Counts and facets cover only eligible candidates (task scan cap 100); count_is_partial labels the cap. Continuation is signed and bound to normalized query, type, identity and current result snapshot. Empty query: nothing searched, 200.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "q"
                ],
                "properties": {
                  "q": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "all",
                      "areas",
                      "tasks"
                    ]
                  },
                  "cursor": {
                    "type": "string",
                    "maxLength": 512
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Grouped results.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Search"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/preferences/theme": {
      "get": {
        "operationId": "getTheme",
        "summary": "The member's theme (OC-075); system follows the device",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Theme and the preferences row version.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Theme"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "patch": {
        "operationId": "updateTheme",
        "summary": "Save the member's theme (OC-075)",
        "description": "Same rules as PATCH /api/v1/preferences (shared row version; repeat 200; stale 409).",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "Origin",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-CSRF-Token",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "theme",
                  "version"
                ],
                "properties": {
                  "theme": {
                    "enum": [
                      "system",
                      "light",
                      "dark"
                    ]
                  },
                  "version": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved (or already applied).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Theme"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{id}/members": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "listWorkspaceMembers",
        "summary": "Members of the session's current workspace (OC-003)",
        "description": "Only the current workspace id is accepted; any other id (foreign, unknown, malformed) returns the same 404. Owners/admins also see invited members.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Members (opaque membership ids and roles; no global identity).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Members"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/client-errors": {
      "post": {
        "operationId": "reportClientError",
        "summary": "One browser error report (OC-OBSERVABILITY; public, no session)",
        "description": "window error, unhandledrejection or the React error boundary. Same origin only (Origin names the request's host and, when APP_URL is set, an environment origin), JSON <= 8 KB with keys type, message, stack, path, source (onerror | unhandledrejection | boundary). Scrubbed and grouped server-side; 20 per network digest and 600 overall per minute. docs/ops/observability.md.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "message"
                ],
                "properties": {
                  "type": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1
                  },
                  "stack": {
                    "type": "string"
                  },
                  "path": {
                    "type": "string"
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "onerror",
                      "unhandledrejection",
                      "boundary"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted: {\"status\":\"accepted\",\"request_id\"}."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "413": {
            "$ref": "#/components/responses/Error"
          },
          "415": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/admin/errors": {
      "get": {
        "operationId": "listErrorGroups",
        "summary": "Owner-only error groups and 24 h activity summary (OC-OBSERVABILITY)",
        "description": "Only for the platform owner hi@openclone.fun (OC-OWNER-HI; dev also the synthetic e2e owner) on a session created by a magic link, configured by OWNER_EMAIL_SHA256 / OWNER_USER_IDS; a password, Google, WhatsApp-code or pre-0012 session, and everyone else, gets 404. Query kind (backend | http5xx | js), status (new | open | resolved | regressed), window (24h | 7d). Answer {groups[], summary {hours[24], requests, errors, error_rate, p95_ms, signed_in}, window, release}.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Groups (new and regressed first) and the activity summary."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/admin/errors/{signature}": {
      "parameters": [
        {
          "name": "signature",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}$"
          }
        }
      ],
      "get": {
        "operationId": "getErrorGroup",
        "summary": "Owner-only group with its newest 20 scrubbed samples and hourly counts",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{group, samples[], hourly[]}."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "operationId": "setErrorGroupStatus",
        "summary": "Owner-only: {\"status\": \"open\" | \"resolved\"} (exact origin + CSRF)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{group}."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/admin/errors/test": {
      "post": {
        "operationId": "ownerTestError",
        "summary": "Owner-only (magic-link session of hi@openclone.fun): {\"kind\": \"backend\"} answers a real 500 from a synthetic exception (proves capture end to end); with \"probe\" (6-24 lower-case letters) it is an alert check: a new group, one alert e-mail to hi@openclone.fun",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "500": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/metrics/hit": {
      "post": {
        "operationId": "metricsHit",
        "summary": "Cookie-free first-party page view (OC-GROUP-ADMIN; public, no session, always 204)",
        "description": "Same origin only (Origin names the request's host, Sec-Fetch-Site same-origin), body <= 512 bytes, JSON {\"p\": path without query, \"r\": referring domain or \"\"} (sent by navigator.sendBeacon as text/plain). Always 204 without a body, cookie or CORS header, also when ignored. Bots, automation, internal networks (GROUP_METRICS_INTERNAL_CIDRS), x-internal-traffic: 1 and sessions of test/seed/internal accounts only add to the day's excluded counters. Unique visitors = SHA-256(daily salt || \"openclone\" || ip || user agent || accept-language), the salt and hashes deleted when the Europe/Lisbon day closes; the IP and user agent are never stored or logged. docs/product/group-admin.md.",
        "requestBody": {
          "required": true,
          "content": {
            "text/plain": {
              "schema": {
                "type": "string",
                "maxLength": 512
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Recorded, excluded or ignored (indistinguishable)."
          },
          "405": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/internal/group-admin/v1/{route}": {
      "parameters": [
        {
          "name": "route",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "enum": [
              "manifest",
              "summary",
              "resources",
              "resources/users",
              "resources/users/{id}",
              "audit",
              "metrics/daily",
              "errors/recent"
            ]
          }
        }
      ],
      "get": {
        "operationId": "groupAdmin",
        "summary": "Signed server-to-server reads of the group admin console (OC-GROUP-ADMIN; contract v1 + v2 metrics.daily, errors.recent)",
        "description": "BU-ADMIN-HMAC-SHA256/v1 headers x-bu-admin-key-id, -timestamp (+-60 s), -nonce (single use, 300 s), -body-sha256, -signature, -contract-version (1.0.0 | 2.0.0) and optional x-group-admin-actor; keys per environment in GROUP_ADMIN_KEYS. No cookie or session is read. Every answer has Cache-Control no-store and X-Robots-Tag noindex; errors are {\"error\":{\"code\",\"message\",\"requestId\"}}: unauthorized 401 (any signing failure, generic), not_found 404 (unknown route, POST /operations/*, client IP not in GROUP_ADMIN_ALLOWED_IPS), invalid_request / invalid_range / range_too_large 400, env_mismatch 409, rate_limited 429 (60/min per key id), not_configured 503 (no key), unavailable 503. metrics/daily takes from, to (YYYY-MM-DD, inclusive, to <= today, <= 400 days) and tz (Europe/Lisbon | UTC). errors/recent (OC-ERRORS-RECENT) takes since (ISO-8601 date-time with Z or an offset, at most 31 days back), limit (1..100, default 100) and the opaque cursor ([A-Za-z0-9._~-]{1,512}) of the previous page; a bad since, limit or cursor is 422 invalid_request. It answers {environment, items[], nextCursor}: one item per error group seen since `since` (app-wide, never a tenant), newest lastSeen first, with exactly group (16 hex), level (fatal | error | warning), count (occurrences in the window, >= 1), firstSeen, lastSeen (UTC Z), route (template like /api/v1/files/:id, or null) and message (\"<Type>: <scrubbed reason>\", <= 200 chars); schema api/schemas/group-admin-errors-recent.schema.json. Contract, definitions and examples: docs/product/group-admin.md.",
        "responses": {
          "200": {
            "description": "manifest {schema: group-admin-v2, capabilities: [metrics.daily, errors.recent], errorsView: /admin/erros, operations: []}, summary, pages {items, nextCursor}, metrics {schema: group-admin-metrics-v1, days[]} or errors {environment, items[], nextCursor}."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals": {
      "get": {
        "operationId": "rentalsSnapshot",
        "summary": "The person's whole rental section (or only the consent step)",
        "description": "Before consent: {consent, capabilities}. After: properties, lessees (IBANs masked), contracts, expected rents with read-time state (due | late | partial | paid | forgiven), movements of the last 400 days with their associations, receipts, imports, bank links, Portal and Drive connection facts (masked NIF only), overview of the current month and Pendentes (payment_suggested, rent_late, consent_expired, payment_unmatched, rent_partial, receipt_to_issue, receipt_without_payment, consent_expiring, original_not_in_drive). Missing expected rents up to next month are created on read.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Snapshot.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rentals"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      },
      "delete": {
        "operationId": "rentalsErase",
        "summary": "Erase the whole section (GDPR)",
        "description": "Body {\"confirm\":\"erase\"}. Deletes every rental row of the person, the vault and the consent in one transaction, then revokes the Drive token and bank consents remotely (best effort). Files in the person's Drive stay theirs. A code-only tenant audit event rental_section.erased remains.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"erased\":{\"rows\",\"drive\",\"banks\"}}"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/consent": {
      "post": {
        "operationId": "rentalsConsent",
        "summary": "Accept the section's purpose and privacy terms (version 2026-10-23)",
        "description": "Body {\"version\"}; another version is 409. Answers the full snapshot.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Snapshot after consent."
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/export": {
      "get": {
        "operationId": "rentalsExport",
        "summary": "Everything of the section in clear, with the opened audit trail (GDPR export, attachment)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"export\":{\"format\":\"openclone-rentals-export/v1\", ...}}"
          }
        }
      }
    },
    "/api/v1/rentals/summary": {
      "get": {
        "operationId": "rentalsSummary",
        "summary": "Yearly summary per property (expected, received, outstanding, receipts issued, late months)",
        "description": "Read-only. Query year=YYYY (default the current year, 2000 .. current year + 1; anything else is 400 invalid_year or year_out_of_range with field \"year\"). Answers {\"summary\":{\"year\",\"as_of\",\"rows\":[{\"property_id\",\"name\",\"currency\", \"expected\",\"received\",\"outstanding\",\"receipts_issued\",\"receipts_amount\",\"late_months\"}],\"totals\":[same per currency]}}. Expected counts the non-forgiven rents of the year that have fallen due (due date up to as_of); received is capped per rent at its amount; receipts are the issued or imported rent receipts of the year. Money is an exact decimal string (never a float) in its own currency. Unknown stays null: a property whose rent got a payment booked in another currency has null received, outstanding and late_months, and that money has its own row in its currency; a total with an unknown part is null. property_id/name are null for receipts not linked to a property. An empty year answers empty rows and totals. Only the signed-in person's own rows are read (tenant and membership); 403 consent_required first.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "year",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "summary"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/summary.csv": {
      "get": {
        "operationId": "rentalsSummaryCsv",
        "summary": "The yearly summary as a UTF-8 CSV (attachment)",
        "description": "Same query and rules as the JSON summary. UTF-8 with BOM, every field quoted, CRLF, text neutralised against spreadsheet formulas (a leading =, +, - or @ gets an apostrophe), decimals copied as exact strings, unknown = empty cell, one TOTAL row per currency at the end.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "year",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "text/csv"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/api/v1/rentals/properties": {
      "post": {
        "operationId": "rentalsCreateProperty",
        "summary": "New property {\"name\", \"address\"?, \"matrix_article\"?, \"fraction\"?, \"landlord_nifs\"?, \"share_pct\"?}",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "{\"id\"}"
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/properties/{id}": {
      "patch": {
        "operationId": "rentalsUpdateProperty",
        "summary": "Replace a property's fields at \"version\" (409 when stale); \"archived\" optional",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/lessees": {
      "post": {
        "operationId": "rentalsCreateLessee",
        "summary": "New tenant {\"name\", \"nif\"? (mod-11), \"email\"?, \"phone\"?, \"ibans\"? (mod-97), \"alt_names\"?}",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "{\"id\"}"
          }
        }
      }
    },
    "/api/v1/rentals/lessees/{id}": {
      "patch": {
        "operationId": "rentalsUpdateLessee",
        "summary": "Replace a tenant's fields at \"version\"; without \"ibans\" the known (never shown in full) IBANs are kept",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/contracts/drafts": {
      "post": {
        "operationId": "rentalsUploadContract",
        "summary": "Upload a contract for review (raw body; PDF, JPEG, PNG, WebP, HEIC or DOCX; <= 3.9 MB; X-File-Name)",
        "description": "Read on this server only (pdftotext / DOCX / tesseract when present), fields extracted with confidence 0..1 and the source snippet; the sealed original is kept 24 h for review (30 days once a contract refers to it and Drive is not connected). 415 unsupported_type / type_mismatch (the bytes decide), 413 too_large, 409 too_many_drafts.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "{\"draft\":{\"id\",\"method\":\"text|docx|ocr|none\",\"name\",\"fields\":{field:{value,confidence,source}}}}"
          }
        }
      }
    },
    "/api/v1/rentals/contracts/drafts/{id}": {
      "delete": {
        "operationId": "rentalsDiscardDraft",
        "summary": "Discard an uploaded contract that was not saved",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/contracts": {
      "post": {
        "operationId": "rentalsCreateContract",
        "summary": "Save a reviewed contract (with an existing or new property and tenants)",
        "description": "{\"property_id\"|\"property\", \"lessee_ids\"|\"lessees\", \"start_date\", \"end_date\"?, \"renewal\":\"auto|none\", \"rent_cents\", \"periodicity\":\"monthly|quarterly|semiannual|annual\", \"due_day\", \"deposit_cents\", \"withholding_bps\" (0..5000), \"at_contract_ref\"?, \"iban\"?, \"landlord_name\"?, \"landlord_nif\"?, \"notes\"?, \"draft_id\"?, \"confidence\"?}. Expected rents are created; the original goes to Arrendamento/<Imóvel>/Contratos in the person's Drive when connected.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "{\"contract\":{\"id\",\"original\":\"none|drive|waiting\"}}"
          }
        }
      }
    },
    "/api/v1/rentals/contracts/{id}": {
      "patch": {
        "operationId": "rentalsPatchContract",
        "summary": "{\"version\", \"end_date\"} ends the contract; or {\"version\", \"at_contract_ref\"?, \"iban\"?, \"notes\"?}",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/rents/{id}/forgive": {
      "post": {
        "operationId": "rentalsForgiveRent",
        "summary": "{\"forgiven\": true|false}",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/statements": {
      "post": {
        "operationId": "rentalsImportStatement",
        "summary": "Import a bank statement (raw body; CSV, OFX/QFX, CAMT.053 or PDF with text; <= 3.9 MB)",
        "description": "Rows are deduplicated per person (bank id or date/amount/text digest); every new incoming movement goes through the association engine (auto >= 75 with amount and payer evidence, suggestion >= 45, else Pendentes). 400 no_rows / unsupported_format / pdf_no_text.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "{\"import\":{\"format\",\"total\",\"new\",\"auto\",\"suggested\",\"skipped\",\"in_drive\"}}"
          }
        }
      }
    },
    "/api/v1/rentals/payments/{id}/{action}": {
      "post": {
        "operationId": "rentalsPaymentAction",
        "summary": "confirm | reject a suggestion, or revert an active association (never deleted)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "confirm",
                "reject",
                "revert"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/transactions/{id}/{action}": {
      "post": {
        "operationId": "rentalsTransactionAction",
        "summary": "assign {\"rent_id\"} (manual association) | ignore {\"ignored\": true|false}",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "assign",
                "ignore"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/receipts": {
      "post": {
        "operationId": "rentalsRecordReceipt",
        "summary": "Record a receipt the person issued on the Portal {\"contract_id\", \"at_number\", \"period\", \"kind\", \"amount_cents\", \"received_on\"}",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "201": {
            "description": "{\"id\"}"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/receipts/{id}/receipt.pdf": {
      "get": {
        "operationId": "rentalsReceiptPdf",
        "summary": "Download ONE stored (issued or imported) receipt as a text PDF; prepared or cancelled receipts answer 409",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "application/pdf"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/receipts/{id}/{action}": {
      "post": {
        "operationId": "rentalsReceiptAction",
        "summary": "summary | issue | record | dismiss ONE receipt (issuing always needs that receipt's own confirmation token)",
        "description": "summary -> {\"confirmation\":{\"summary\",\"digest\",\"token\",\"expires_at\",\"mode\":\"driver|manual|needs_contract_ref\"}}: the exact data to be issued and a token bound to the person, the receipt, its version and the summary digest (10 min, single use). issue {\"token\"}: ONE call to the person's Portal session (simulated on dev), never batch or scheduled; 409 confirmation_required when the token is missing, expired, used, for another receipt or the summary changed. record {\"token\",\"at_number\"}: the person issued it on the Portal themselves. dismiss {\"dismissed\"}. There is no route that issues more than one receipt.",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "action",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "summary",
                "issue",
                "record",
                "dismiss"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/finance": {
      "post": {
        "operationId": "rentalsConnectFinance",
        "summary": "Connect the person's own Portal das Finanças session {\"nif\",\"password\"} (one login; sealed in the vault only when it worked)",
        "description": "422 at_login_failed; 503 not_configured without a driver (APP_AT_DRIVER; the AT webservice is not used).",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "operationId": "rentalsDisconnectFinance",
        "summary": "Delete the Portal credentials from the vault",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/finance/import": {
      "post": {
        "operationId": "rentalsImportReceipts",
        "summary": "Import the receipts issued this and last year (idempotent by AT number; PDFs to the person's Drive)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"import\":{\"new\",\"existing\",\"in_drive\"}}"
          }
        }
      }
    },
    "/api/v1/rentals/bank/banks": {
      "get": {
        "operationId": "rentalsBanks",
        "summary": "Banks the configured AIS provider offers (?country=PT)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"banks\":[{\"name\",\"country\"}]}"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/rentals/bank": {
      "post": {
        "operationId": "rentalsStartBank",
        "summary": "Start a read-only consent at the person's bank {\"bank\",\"country\"} -> {\"url\"} (the bank's own login and SCA)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"url\"}"
          }
        }
      }
    },
    "/api/v1/rentals/bank/callback": {
      "get": {
        "operationId": "rentalsBankCallback",
        "summary": "Back from the bank (?state&code|error) -> 302 /files/rentals/connections?result=...",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect with a result code only."
          }
        }
      }
    },
    "/api/v1/rentals/bank/{id}/sync": {
      "post": {
        "operationId": "rentalsSyncBank",
        "summary": "Read the booked movements of the last 120 days into the engine (409 consent_expired)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "{\"sync\":{\"new\",\"auto\",\"suggested\"}}"
          }
        }
      }
    },
    "/api/v1/rentals/bank/{id}": {
      "delete": {
        "operationId": "rentalsRevokeBank",
        "summary": "Revoke the consent (local use stops first, then the provider is told)",
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/drive": {
      "post": {
        "operationId": "rentalsStartDrive",
        "summary": "Connect the person's own Google Drive (scope drive.file only, PKCE, offline) -> {\"url\"}",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"url\"}"
          },
          "503": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "operationId": "rentalsDisconnectDrive",
        "summary": "Forget and revoke the Drive token (files stay in the person's Drive)",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    },
    "/api/v1/rentals/drive/callback": {
      "get": {
        "operationId": "rentalsDriveCallback",
        "summary": "Back from Google (?state&code|error) -> 302 /files/rentals/connections?result=...",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect with a result code only."
          }
        }
      }
    },
    "/api/v1/rentals/drive/sync": {
      "post": {
        "operationId": "rentalsSyncDrive",
        "summary": "Build/repair Arrendamento/<Imóvel>/{Contratos,Recibos,Pagamentos,Inquilinos,Outros}, send waiting originals, rewrite _índice.json",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{\"sync\":{\"uploaded\"}}"
          }
        }
      }
    },
    "/api/v1/connections/google/gmail/read": {
      "post": {
        "operationId": "enableGmailRead",
        "summary": "Gmail read activation remains blocked for Google restricted-scope and runtime approval.",
        "description": "No OAuth request or content read occurs. Requires the current session, exact origin and CSRF token. Imports remain independent.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "description": "gmail_policy_blocked; gmail.blocked is the localized message key."
          }
        }
      }
    },
    "/api/v1/connections/{connectionId}/mail-coverage": {
      "parameters": [
        {
          "name": "connectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "operationId": "gmailMailCoverage",
        "summary": "Owner-only Gmail coverage; never returns mail, cursor, subject or tokens.",
        "description": "Currently returns coverage state policy_blocked, available false, messages 0 for an owned connection. Another membership or tenant receives 404. Client tenant headers grant no authority.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "{coverage:{state,available,messages}}; private no-store response."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/inbox": {
      "get": {
        "operationId": "unifiedInbox",
        "summary": "Read-only eligible conversation projection (public connector admission blocked)",
        "description": "Session-derived owner only. Private no-store. Optional filter=all|unread|needs_you, limit=1..50 (default 30) and opaque snapshot-bound cursor. Returns available, partial=true, truncated, coverage[], capabilities, threads[], counts and next_cursor. No query text in GET. Public runtime returns available=false and zero counts; a flag change alone cannot activate it.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Authorized bounded projection or truthful unavailable state."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "409": {
            "description": "Cursor is stale or belongs to another authority/filter/query/page size."
          }
        }
      }
    },
    "/api/v1/inbox/counts": {
      "get": {
        "operationId": "unifiedInboxCounts",
        "summary": "Counts from the same authorized bounded projection",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Same metadata/counts as inbox without threads or cursor."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          }
        }
      }
    },
    "/api/v1/inbox/search": {
      "post": {
        "operationId": "unifiedInboxSearch",
        "summary": "Private lexical snippet search, no AI or persistent index",
        "description": "Exact-origin CSRF required. JSON query (max 200 characters), filter, cursor, limit. Filters current account permissions before decrypting or matching. Same response as inbox; counts describe the authorized inbox before the search/filter. Public runtime remains unavailable.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Bounded authorized hits and explicit partial coverage."
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/conversations/{sourceId}": {
      "parameters": [
        {
          "name": "sourceId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      ],
      "get": {
        "operationId": "sourceConversation",
        "summary": "Own source thread with bounded plain-text history and revisions",
        "description": "Source IDs are tenant/member/account scoped and distinct from UUID automation-policy IDs. Returns thread plus coverage/capabilities. Messages have direction, at, source_revision, state=source, delivery_verified=false, attachments=[], reactions_available=false. GET /conversations/{sourceId}/messages returns the same bounded thread envelope. POST /conversations/{sourceId}/sync requires CSRF but remains unavailable (409 for admitted own resources, 404 otherwise); it never launches a job or provider call.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "At most the owning account's 500 selected snippets, ordered by time and source ID."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "description": "Unknown, forbidden, revoked or publicly blocked source."
          }
        }
      }
    },
    "/api/v1/inbox/events": {
      "get": {
        "operationId": "inboxEventsUnavailable",
        "summary": "No admitted inbox SSE transport",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "409": {
            "description": "No stream or private event replay; Last-Event-ID confers no authority."
          }
        }
      }
    },
    "/api/v1/attachments/{sourceAttachmentId}": {
      "parameters": [
        {
          "name": "sourceAttachmentId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "sourceAttachmentUnavailable",
        "summary": "No media references admitted by the snippet-only connector",
        "description": "The /download suffix also returns 404. No provider URL fetch or alternative storage path.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "description": "No admitted authorized attachment."
          }
        }
      }
    },
    "/api/v1/messages/{sourceMessageId}/reactions": {
      "parameters": [
        {
          "name": "sourceMessageId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          }
        }
      ],
      "post": {
        "operationId": "sourceReactionUnavailable",
        "summary": "No reaction capability in the Gmail read adapter",
        "description": "Exact-origin CSRF required. Unknown/unavailable sources return 404; an internally admitted own message returns conflict, never sent/done.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/{path}": {
      "parameters": [
        {
          "name": "path",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "v1Other",
        "summary": "Any other private path",
        "description": "Without a well-formed session cookie every /api/v1 request returns the same 401 regardless of path, method or client tenant headers. With a valid session, unknown paths return 404.",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-oc_session",
        "description": "Host-only session cookie (__Host-, Secure, HttpOnly, SameSite=Lax); issued by sign-in (IMPL-003) and workspace switch. Writes also need X-CSRF-Token (= __Host-oc_csrf) and the exact session origin."
      }
    },
    "responses": {
      "Error": {
        "description": "Error envelope.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthenticated": {
        "description": "No valid session (same body for every path and method).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Database unavailable or not configured for this environment.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Obligations": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$defs": {
          "wait": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "task_id",
              "version",
              "goal",
              "kind",
              "status",
              "due_at",
              "timezone",
              "quiet_start",
              "quiet_end",
              "max_count",
              "source_revision"
            ],
            "properties": {
              "task_id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "integer",
                "minimum": 1
              },
              "goal": {
                "type": "string"
              },
              "kind": {
                "enum": [
                  "reply",
                  "file",
                  "date",
                  "user"
                ]
              },
              "status": {
                "enum": [
                  "waiting",
                  "reminder",
                  "received",
                  "cancelled"
                ]
              },
              "due_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "timezone": {
                "type": "string"
              },
              "quiet_start": {
                "type": "integer",
                "minimum": 0,
                "maximum": 23
              },
              "quiet_end": {
                "type": "integer",
                "minimum": 0,
                "maximum": 23
              },
              "max_count": {
                "enum": [
                  0,
                  1
                ]
              },
              "source_revision": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 1
              },
              "snoozed_until": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "wait_input": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "version",
              "kind",
              "due_at",
              "timezone"
            ],
            "properties": {
              "version": {
                "type": "integer",
                "minimum": 0
              },
              "kind": {
                "enum": [
                  "reply",
                  "file",
                  "date",
                  "user"
                ]
              },
              "due_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "timezone": {
                "type": "string"
              }
            }
          },
          "followup_policy": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "version",
              "quiet_start",
              "quiet_end",
              "max_count"
            ],
            "properties": {
              "version": {
                "type": "integer",
                "minimum": 1
              },
              "quiet_start": {
                "type": "integer",
                "minimum": 0,
                "maximum": 23
              },
              "quiet_end": {
                "type": "integer",
                "minimum": 0,
                "maximum": 23
              },
              "max_count": {
                "enum": [
                  0,
                  1
                ]
              }
            }
          },
          "auto_setting": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "conversation_id",
              "version",
              "enabled"
            ],
            "properties": {
              "conversation_id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "integer",
                "minimum": 0
              },
              "enabled": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "DriveRoot": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Own Drive availability (not activated)",
        "type": "object",
        "required": [
          "available",
          "root",
          "reason",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "available": {
            "const": false
          },
          "root": {
            "type": "null"
          },
          "reason": {
            "const": "runtime_not_activated"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "Action": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Action proof envelope",
        "type": "object",
        "required": [
          "action",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "action": {
            "$ref": "#/components/schemas/Action/$defs/action"
          },
          "request_id": {
            "type": "string"
          }
        },
        "$defs": {
          "action": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "task_id",
              "state",
              "complete",
              "verified_at",
              "source_available",
              "timeline"
            ],
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "task_id": {
                "type": "string",
                "format": "uuid"
              },
              "state": {
                "enum": [
                  "queued",
                  "sending",
                  "checking",
                  "accepted",
                  "sent",
                  "delivered",
                  "read",
                  "cancelled",
                  "failed"
                ]
              },
              "complete": {
                "type": "boolean"
              },
              "verified_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "source_available": {
                "type": "boolean"
              },
              "timeline": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "state",
                    "at",
                    "source_available"
                  ],
                  "properties": {
                    "state": {
                      "enum": [
                        "queued",
                        "sending",
                        "checking",
                        "accepted",
                        "sent",
                        "delivered",
                        "read",
                        "cancelled",
                        "failed"
                      ]
                    },
                    "at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "source_available": {
                      "type": "boolean"
                    }
                  }
                }
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "complete": {
                      "const": true
                    }
                  }
                },
                "then": {
                  "properties": {
                    "state": {
                      "enum": [
                        "sent",
                        "delivered",
                        "read"
                      ]
                    },
                    "source_available": {
                      "const": true
                    },
                    "verified_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              },
              {
                "if": {
                  "properties": {
                    "state": {
                      "enum": [
                        "accepted",
                        "sent",
                        "delivered",
                        "read",
                        "failed"
                      ]
                    }
                  }
                },
                "then": {
                  "properties": {
                    "verified_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            ]
          },
          "event": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "state",
              "at",
              "source_available"
            ],
            "properties": {
              "state": {
                "enum": [
                  "queued",
                  "sending",
                  "checking",
                  "accepted",
                  "sent",
                  "delivered",
                  "read",
                  "cancelled",
                  "failed"
                ]
              },
              "at": {
                "type": "string",
                "format": "date-time"
              },
              "source_available": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "Revision": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Revision",
        "description": "GET /api/revision deploy truth contract (spec E.6, L.2 step 6).",
        "type": "object",
        "required": [
          "app",
          "env",
          "revision"
        ],
        "additionalProperties": false,
        "properties": {
          "app": {
            "const": "openclone"
          },
          "env": {
            "enum": [
              "dev",
              "prod"
            ]
          },
          "revision": {
            "type": "string",
            "pattern": "^[0-9a-f]{40}$"
          }
        }
      },
      "Error": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "ErrorEnvelope",
        "description": "Error envelope (spec E.6). The browser translates message_key; details are allowlisted.",
        "type": "object",
        "required": [
          "error"
        ],
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message_key",
              "request_id",
              "retryable",
              "details"
            ],
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{1,63}$"
              },
              "message_key": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_.]{1,127}$"
              },
              "request_id": {
                "type": "string",
                "pattern": "^req_[0-9a-f]{24}$"
              },
              "retryable": {
                "type": "boolean"
              },
              "details": {
                "type": "object"
              }
            }
          }
        }
      },
      "Healthz": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "PublicHealth",
        "description": "GET /api/healthz public health (OC-078). No credentials, tenant details or internal dependency dumps. mail is 'configured' when the SMTP/APP_URL settings are complete for this environment; health never connects to the mail server or sends mail. signin is 'configured' only when database, mail and the sign-in key material (APP_KEK, APP_AUTH_KEY) are all present for this release's environment; it never proves a sign-in works. storage/media report object-storage configuration and encoder capabilities only, never a setting value.",
        "type": "object",
        "required": [
          "app",
          "status",
          "env",
          "revision",
          "checks",
          "inference",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "app": {
            "const": "openclone"
          },
          "status": {
            "enum": [
              "ok",
              "unavailable"
            ]
          },
          "env": {
            "enum": [
              "dev",
              "prod",
              null
            ]
          },
          "revision": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9a-f]{40}$"
          },
          "checks": {
            "type": "object",
            "required": [
              "release",
              "database",
              "mail",
              "signin",
              "google",
              "apple",
              "worker",
              "inference",
              "storage",
              "media",
              "group_admin",
              "whatsapp",
              "rentals"
            ],
            "additionalProperties": false,
            "properties": {
              "release": {
                "enum": [
                  "ok",
                  "unavailable"
                ]
              },
              "database": {
                "enum": [
                  "ok",
                  "unavailable",
                  "not_configured"
                ]
              },
              "mail": {
                "enum": [
                  "configured",
                  "unavailable",
                  "not_configured"
                ]
              },
              "signin": {
                "enum": [
                  "configured",
                  "unavailable",
                  "not_configured"
                ]
              },
              "google": {
                "enum": [
                  "configured",
                  "unavailable",
                  "not_configured"
                ],
                "description": "\"Continue with Google\" (SLICE-A-SITE): configured only when GOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET are valid for this release's environment AND signin is configured; the app shows the Google button only then (hidden otherwise, never disabled)."
              },
              "apple": {
                "enum": [
                  "configured",
                  "unavailable",
                  "not_configured"
                ],
                "description": "\"Continue with Apple\" (OC-APPLE-SIGNIN): configured only when APP_APPLE_SERVICES_ID, APP_APPLE_TEAM_ID, APP_APPLE_KEY_ID and the private key are valid for this release's environment AND signin is configured; not_configured without APP_APPLE_SERVICES_ID (the button is hidden, never disabled)."
              },
              "worker": {
                "description": "Scheduler process observation only. A running worker heartbeat in the last 120 seconds is ok. No observed worker is not_configured; stale, stopped or unreadable telemetry is unavailable.",
                "enum": [
                  "ok",
                  "unavailable",
                  "not_configured"
                ]
              },
              "inference": {
                "description": "A declared public inference gate that is off is held. An enabled gate without a verified runtime is unavailable. No declared gate is not_configured. No inference request is made.",
                "enum": [
                  "ok",
                  "held",
                  "unavailable",
                  "not_configured"
                ]
              },
              "storage": {
                "enum": [
                  "configured",
                  "unavailable",
                  "not_configured"
                ],
                "description": "Private object storage for user files (IMPL-B2-STORAGE, Backblaze B2 S3 API): configured only when every required B2_* setting is valid for this release's environment; health never contacts the store. Without it uploads are refused (fail closed)."
              },
              "media": {
                "type": "object",
                "required": [
                  "image",
                  "video"
                ],
                "additionalProperties": false,
                "description": "Media encoders on this host: image 'avif+webp' only when BOTH encoders exist (Imagick, GD or ffmpeg); video 'h264' when ffmpeg/ffprobe (FFMPEG_PATH/FFPROBE_PATH, /usr/bin, /usr/local/bin, PATH) with libx264, aac and libwebp exist. 'unavailable' = uploads of that kind are refused; video_reason (only with video 'unavailable') is a code, never a path.",
                "properties": {
                  "image": {
                    "enum": [
                      "avif+webp",
                      "unavailable"
                    ]
                  },
                  "video": {
                    "enum": [
                      "h264",
                      "unavailable"
                    ]
                  },
                  "video_reason": {
                    "enum": [
                      "proc_open_disabled",
                      "ffmpeg_missing",
                      "ffprobe_missing",
                      "encoders_unreadable",
                      "missing_libx264",
                      "missing_aac",
                      "missing_libwebp"
                    ]
                  }
                }
              },
              "group_admin": {
                "enum": [
                  "configured",
                  "not_configured"
                ],
                "description": "Group admin console adapter (OC-GROUP-ADMIN): configured when GROUP_ADMIN_KEYS holds at least one valid key for this release's environment. Never a key id, secret or count."
              },
              "whatsapp": {
                "enum": [
                  "ok",
                  "not_configured",
                  "unreachable"
                ],
                "description": "WhatsApp login (OC-LOGIN-WHATSAPP): ok when APP_WHATSAPP_PROVIDER=group, WA_GATEWAY_* are valid and the group WhatsApp gateway's unsigned health answers (cached 60 s); never blocks readiness and never names the gateway. There is no SMS check: phone login is a WhatsApp message only."
              },
              "rentals": {
                "type": "object",
                "required": [
                  "drive",
                  "finance",
                  "bank"
                ],
                "additionalProperties": false,
                "description": "Rental section providers (OC-ARRENDAMENTO, docs/product/rentals.md): drive configured when the environment's Google OAuth client exists (scope drive.file, each person connects their own Drive); finance simulated (dev-only simulated Portal das Finanças) or manual (no driver: the person issues on the Portal and records the receipt number; the AT webservice is not used); bank statements_only (free statement import), simulated (dev sandbox bank) or enablebanking_sandbox/enablebanking_production (production only with the banking_ais flag, i.e. a licensed AISP contract). Names and states only.",
                "properties": {
                  "drive": {
                    "enum": [
                      "configured",
                      "not_configured"
                    ]
                  },
                  "finance": {
                    "enum": [
                      "simulated",
                      "manual"
                    ]
                  },
                  "bank": {
                    "enum": [
                      "statements_only",
                      "simulated",
                      "enablebanking_sandbox",
                      "enablebanking_production"
                    ]
                  }
                }
              }
            }
          },
          "inference": {
            "type": "object",
            "required": [
              "provider",
              "model",
              "status",
              "last_error_at"
            ],
            "additionalProperties": false,
            "description": "In-app AI status, names and states only, from local state (never a provider call, key, URL, prompt or user data). provider/model name the routed subscription provider and model, null while no provider adapter is installed. status: available, not_configured (no installed provider), quota_exceeded (last recorded provider answer was a quota/429) or error (last recorded provider failure). last_error_at is the ISO 8601 UTC time of the last recorded provider failure, or null.",
            "properties": {
              "provider": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "model": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "status": {
                "enum": [
                  "available",
                  "not_configured",
                  "quota_exceeded",
                  "error"
                ]
              },
              "last_error_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "MagicLinkRequest": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "MagicLinkRequest",
        "description": "POST /api/v1/auth/magic-links (alias /api/auth/magic-link) body (OC-001). Unknown fields are rejected. lang selects the e-mail language (default: Accept-Language, else pt-PT). return_to is a same-origin app path returned after sign-in. terms_version and privacy_version (SLICE-A-SITE) are the Terms and Privacy policy versions shown next to the consent box the person ticked: both required (else 400 consent_required), both current (else 409 terms_changed); the account created by this link stores them with the acceptance time, and an existing account records newer versions at sign-in.",
        "type": "object",
        "required": [
          "email",
          "terms_version",
          "privacy_version"
        ],
        "additionalProperties": false,
        "properties": {
          "email": {
            "type": "string",
            "maxLength": 254,
            "pattern": "^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?\\.)+([A-Za-z]{2,63}|xn--[A-Za-z0-9-]{1,59})$"
          },
          "lang": {
            "enum": [
              "pt-PT",
              "en",
              "es",
              "fr",
              "de",
              "it",
              "nl",
              "pl",
              "he",
              "ar",
              "zh-CN",
              "ja",
              "ko",
              "ru",
              "uk",
              "tr"
            ]
          },
          "return_to": {
            "type": "string",
            "maxLength": 200,
            "pattern": "^/(?![/\\\\])[A-Za-z0-9/_.~%=&?-]*$"
          },
          "terms_version": {
            "type": "string",
            "pattern": "^[0-9]{1,8}$"
          },
          "privacy_version": {
            "type": "string",
            "pattern": "^[0-9]{1,8}$"
          }
        }
      },
      "MagicLinkAccepted": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "MagicLinkAccepted",
        "description": "POST /api/auth/magic-link 202 body: the SMTP server accepted the message (250 after DATA). Not a delivery claim. Never contains the token, link, address or any setting.",
        "type": "object",
        "required": [
          "status",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "status": {
            "const": "accepted"
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "MagicLinkConsume": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "MagicLinkConsume",
        "description": "POST /api/v1/auth/magic-links/consume body (OC-001). Sent by the app page the link opened, from the same origin and browser that asked for it. Unknown fields are rejected. time_zone (IANA) and lang are account defaults used only when this sign-in creates the account.",
        "type": "object",
        "required": [
          "token"
        ],
        "additionalProperties": false,
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "time_zone": {
            "type": "string",
            "maxLength": 64
          },
          "lang": {
            "enum": [
              "pt-PT",
              "en",
              "es",
              "fr",
              "de",
              "it",
              "nl",
              "pl",
              "he",
              "ar",
              "zh-CN",
              "ja",
              "ko",
              "ru",
              "uk",
              "tr"
            ]
          }
        }
      },
      "SignedIn": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "SignedIn",
        "description": "POST /api/v1/auth/magic-links/consume 200 body. The session token is only in the HttpOnly Set-Cookie header; csrf_token is also set as the __Host-oc_csrf cookie. created = this sign-in created the personal account.",
        "type": "object",
        "required": [
          "status",
          "created",
          "return_to",
          "csrf_token",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "status": {
            "const": "signed_in"
          },
          "created": {
            "type": "boolean"
          },
          "return_to": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "csrf_token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "GoogleStart": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "GoogleStart",
        "description": "POST /api/v1/auth/google/start body and answer (SLICE-A-SITE). Request: explicit consent (terms_version, privacy_version, both current), optional lang/time_zone for a new account and a same-origin return_to. Answer: the Google authorize URL (scopes openid email, PKCE S256, one-use state bound to this browser and host).",
        "type": "object",
        "required": [
          "status",
          "authorize_url",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "status": {
            "const": "redirect"
          },
          "authorize_url": {
            "type": "string",
            "pattern": "^https?://"
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Me": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Me",
        "description": "GET /api/v1/me 200 body (OC-001): the signed-in identity's own address (opened from its sealed profile), account defaults, current workspace and session id. Never another account's data.",
        "type": "object",
        "required": [
          "user",
          "workspace",
          "session",
          "founder",
          "entitlements",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "user": {
            "type": "object",
            "required": [
              "email",
              "phone",
              "locale",
              "time_zone",
              "created_at"
            ],
            "additionalProperties": false,
            "properties": {
              "email": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 254,
                "description": "null for an account created by WhatsApp login that has no e-mail yet"
              },
              "phone": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 40,
                "description": "The linked WhatsApp number, masked (+351 9•• ••• •12); null without one (OC-LOGIN-WHATSAPP)"
              },
              "locale": {
                "enum": [
                  "pt-PT",
                  "en",
                  "es",
                  "fr",
                  "de",
                  "it",
                  "nl",
                  "pl",
                  "he",
                  "ar",
                  "zh-CN",
                  "ja",
                  "ko",
                  "ru",
                  "uk",
                  "tr"
                ]
              },
              "time_zone": {
                "type": "string",
                "maxLength": 64
              },
              "created_at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "apple": {
                "type": [
                  "object",
                  "null"
                ],
                "required": [
                  "private_relay"
                ],
                "additionalProperties": false,
                "properties": {
                  "private_relay": {
                    "type": "boolean"
                  }
                }
              }
            }
          },
          "workspace": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "role"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "personal",
                  "household",
                  "team"
                ]
              },
              "role": {
                "enum": [
                  "owner",
                  "admin",
                  "member",
                  "viewer"
                ]
              }
            }
          },
          "session": {
            "type": "object",
            "required": [
              "id"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              }
            }
          },
          "founder": {
            "description": "Founders programme (OC-FOUNDERS-1000): the account's founder number while it holds founder status; null for every other account (and after an ops revocation).",
            "type": [
              "object",
              "null"
            ],
            "required": [
              "number",
              "since"
            ],
            "additionalProperties": false,
            "properties": {
              "number": {
                "type": "integer",
                "minimum": 1,
                "maximum": 1000
              },
              "since": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              }
            }
          },
          "entitlements": {
            "description": "From the one Entitlements service: premium = founder OR an active paid plan (none exist today); billable is always false for founders.",
            "type": "object",
            "required": [
              "premium",
              "basis",
              "billable"
            ],
            "additionalProperties": false,
            "properties": {
              "premium": {
                "type": "boolean"
              },
              "basis": {
                "enum": [
                  "founder",
                  "plan",
                  null
                ]
              },
              "billable": {
                "type": "boolean"
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          },
          "offline": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "user",
              "tenant",
              "generation"
            ],
            "description": "Non-secret freshness binding for device-local command intake; not authentication. Session rotation changes generation.",
            "properties": {
              "user": {
                "type": "string",
                "format": "uuid"
              },
              "tenant": {
                "type": "string",
                "format": "uuid"
              },
              "generation": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            }
          }
        }
      },
      "Sessions": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Sessions",
        "description": "GET /api/v1/sessions 200 body (OC-002): the identity's live sessions on every device, newest use first (at most 50). surface is site or app, never a host; no IP address is stored or returned. last_seen_at is coarse (5 minutes).",
        "type": "object",
        "required": [
          "sessions",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "sessions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "label",
                "surface",
                "created_at",
                "last_seen_at",
                "current"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
                },
                "label": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 64
                },
                "surface": {
                  "enum": [
                    "site",
                    "app"
                  ]
                },
                "created_at": {
                  "type": "string",
                  "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
                },
                "last_seen_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
                },
                "current": {
                  "type": "boolean"
                }
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "SessionsIdlePolicy": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "IdlePolicy",
        "description": "GET/PATCH /api/v1/sessions/idle-policy 200 body (OC-SESSIONS-AUTO-EXPIRE): the member's idle sign-out threshold in days; null = never sign out idle devices. A member who never chose reads the default (90).",
        "type": "object",
        "required": [
          "idle_policy",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "idle_policy": {
            "type": "object",
            "required": [
              "idle_days"
            ],
            "additionalProperties": false,
            "properties": {
              "idle_days": {
                "type": [
                  "integer",
                  "null"
                ],
                "enum": [
                  30,
                  60,
                  90,
                  null
                ]
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Workspaces": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "WorkspaceList",
        "description": "GET /api/v1/workspaces (OC-003). Opaque tenant ids; no counts or content of other workspaces.",
        "type": "object",
        "required": [
          "workspaces",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "workspaces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Workspaces/$defs/workspace"
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        },
        "$defs": {
          "workspace": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "role",
              "current"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "personal",
                  "household",
                  "team"
                ]
              },
              "role": {
                "enum": [
                  "owner",
                  "admin",
                  "member",
                  "viewer"
                ]
              },
              "current": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "WorkspaceSwitch": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "WorkspaceSwitch",
        "description": "POST /api/v1/workspaces/switch 200 body. The session token is only in the Set-Cookie header.",
        "type": "object",
        "required": [
          "workspace",
          "csrf_token",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "workspace": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "role",
              "current"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "personal",
                  "household",
                  "team"
                ]
              },
              "role": {
                "enum": [
                  "owner",
                  "admin",
                  "member",
                  "viewer"
                ]
              },
              "current": {
                "const": true
              }
            }
          },
          "csrf_token": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{43}$"
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Preferences": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Preferences",
        "description": "GET/PATCH /api/v1/preferences 200 body (OC-074). The current member's own preferences; null = not chosen (the device decides). Language never implies country, residence, tax rules, currency or time zone.",
        "type": "object",
        "required": [
          "preferences",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "preferences": {
            "type": "object",
            "required": [
              "ui_locale",
              "format_locale",
              "time_zone",
              "version"
            ],
            "additionalProperties": false,
            "properties": {
              "ui_locale": {
                "enum": [
                  null,
                  "pt-PT",
                  "en",
                  "es",
                  "fr",
                  "de",
                  "it",
                  "nl",
                  "pl",
                  "he",
                  "ar",
                  "zh-CN",
                  "ja",
                  "ko",
                  "ru",
                  "uk",
                  "tr"
                ]
              },
              "format_locale": {
                "enum": [
                  null,
                  "pt-PT",
                  "en",
                  "es",
                  "fr",
                  "de",
                  "it",
                  "nl",
                  "pl",
                  "he",
                  "ar",
                  "zh-CN",
                  "ja",
                  "ko",
                  "ru",
                  "uk",
                  "tr"
                ]
              },
              "time_zone": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 64,
                "pattern": "^[A-Za-z0-9_+/-]+$"
              },
              "version": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Today": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Today",
        "description": "GET /api/v1/today (?view=all) 200 body (OC-005). At most three cards (view=all: every visible need), one per underlying need, deterministic order; codes and opaque ids only. quiet=true ('All set') only with complete coverage and nothing pending.",
        "type": "object",
        "required": [
          "today",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "today": {
            "type": "object",
            "required": [
              "cards",
              "more",
              "total",
              "hidden",
              "quiet",
              "coverage"
            ],
            "additionalProperties": false,
            "properties": {
              "cards": {
                "type": "array",
                "maxItems": 50,
                "items": {
                  "type": "object",
                  "required": [
                    "source",
                    "class",
                    "reason",
                    "revision",
                    "due_at",
                    "action",
                    "provider",
                    "hideable"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "source": {
                      "type": "string",
                      "pattern": "^[a-z_]{1,24}\\.[0-9a-f-]{36}$"
                    },
                    "class": {
                      "enum": [
                        "approval",
                        "deadline",
                        "connection",
                        "review"
                      ]
                    },
                    "reason": {
                      "type": "string",
                      "pattern": "^[a-z_.]{1,48}$"
                    },
                    "revision": {
                      "type": "integer",
                      "minimum": 1
                    },
                    "due_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                    },
                    "action": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^[a-z_]{1,24}$"
                    },
                    "provider": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "pattern": "^[a-z_]{1,24}$"
                    },
                    "hideable": {
                      "type": "boolean"
                    }
                  }
                }
              },
              "more": {
                "type": "integer",
                "minimum": 0
              },
              "total": {
                "type": "integer",
                "minimum": 0
              },
              "hidden": {
                "type": "integer",
                "minimum": 0
              },
              "quiet": {
                "type": "boolean"
              },
              "coverage": {
                "type": "object",
                "required": [
                  "state",
                  "sources"
                ],
                "additionalProperties": false,
                "properties": {
                  "state": {
                    "enum": [
                      "none",
                      "partial",
                      "complete"
                    ]
                  },
                  "sources": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "id",
                        "provider",
                        "state",
                        "destinations",
                        "checked_at"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "id": {
                          "enum": [
                            "gmail",
                            "calendar",
                            "drive",
                            "contacts",
                            "telegram",
                            "whatsapp"
                          ]
                        },
                        "provider": {
                          "enum": [
                            "google",
                            "telegram",
                            "whatsapp",
                            "instagram"
                          ]
                        },
                        "state": {
                          "enum": [
                            "not_connected",
                            "connecting",
                            "connected",
                            "needs_permission",
                            "reconnect",
                            "unavailable"
                          ]
                        },
                        "destinations": {
                          "type": "array",
                          "items": {
                            "enum": [
                              "today",
                              "inbox",
                              "tasks",
                              "people",
                              "files"
                            ]
                          }
                        },
                        "checked_at": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Activity": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Activity",
        "description": "GET /api/v1/activity 200 body (OC-005): the member's own recorded events, newest first, codes and times only.",
        "type": "object",
        "required": [
          "activity",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "activity": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "type",
                "at"
              ],
              "additionalProperties": false,
              "properties": {
                "type": {
                  "enum": [
                    "account.created",
                    "session.created",
                    "session.revoked",
                    "session.revoked_others",
                    "session.ended",
                    "preferences.updated",
                    "context.created",
                    "context.updated",
                    "context.archived",
                    "connection.connected",
                    "card.hidden"
                  ]
                },
                "at": {
                  "type": "string",
                  "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                }
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Sources": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Sources",
        "description": "GET /api/v1/sources 200 body (OC-005/OC-075 coverage containers): every source the shell knows with the member's own connection state; 'unavailable' when its connector is not released here.",
        "type": "object",
        "required": [
          "sources",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "provider",
                "state",
                "destinations",
                "checked_at"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "enum": [
                    "gmail",
                    "calendar",
                    "drive",
                    "contacts",
                    "telegram",
                    "whatsapp"
                  ]
                },
                "provider": {
                  "enum": [
                    "google",
                    "telegram",
                    "whatsapp",
                    "instagram"
                  ]
                },
                "state": {
                  "enum": [
                    "not_connected",
                    "connecting",
                    "connected",
                    "needs_permission",
                    "reconnect",
                    "unavailable"
                  ]
                },
                "destinations": {
                  "type": "array",
                  "items": {
                    "enum": [
                      "today",
                      "inbox",
                      "tasks",
                      "people",
                      "files"
                    ]
                  }
                },
                "checked_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                }
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Files": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "FilesList",
        "description": "GET /api/v1/files 200 (IMPL-B2-STORAGE): newest ready files with fresh signed URLs, uploads in progress or failed (last 24 h), the signed-URL TTL and which kinds this host can process. available=false (and empty lists) when private storage is not configured here.",
        "type": "object",
        "required": [
          "available",
          "files",
          "uploads",
          "ttl",
          "capabilities",
          "request_id",
          "next_cursor"
        ],
        "additionalProperties": false,
        "properties": {
          "available": {
            "type": "boolean"
          },
          "files": {
            "type": "array",
            "maxItems": 40,
            "items": {
              "$ref": "#/components/schemas/Files/$defs/file"
            }
          },
          "uploads": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/Files/$defs/upload"
            }
          },
          "ttl": {
            "type": "integer",
            "minimum": 0,
            "maximum": 3600
          },
          "capabilities": {
            "type": "object",
            "required": [
              "image",
              "video"
            ],
            "additionalProperties": false,
            "properties": {
              "image": {
                "type": "boolean"
              },
              "video": {
                "type": "boolean"
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 512,
            "description": "Opaque continuation for the next 40 ready files; null when exhausted."
          }
        },
        "$defs": {
          "upload": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "name",
              "size",
              "state",
              "error",
              "retryable",
              "file_id",
              "created_at"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "state": {
                "enum": [
                  "issued",
                  "uploaded",
                  "processing",
                  "ready",
                  "failed",
                  "expired",
                  "deleted"
                ]
              },
              "error": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Failure code when state is failed: type_mismatch, size_mismatch, unsupported, corrupt, too_many_pixels, too_long (final) or processing_failed, encoder_missing, encoder_failed, transcode_failed, timeout, storage_unavailable (retryable)."
              },
              "retryable": {
                "type": "boolean"
              },
              "file_id": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              }
            }
          },
          "variant": {
            "type": "object",
            "required": [
              "variant",
              "format",
              "mime",
              "size",
              "width",
              "height",
              "url"
            ],
            "additionalProperties": false,
            "properties": {
              "variant": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,16}$"
              },
              "format": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,8}$"
              },
              "mime": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 0
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "url": {
                "type": "string",
                "description": "Presigned GET (SigV4 query, X-Amz-Expires <= B2_SIGNED_URL_TTL, max 3600 s) on the private bucket; never a permanent URL."
              }
            }
          },
          "file": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "type",
              "name",
              "size",
              "width",
              "height",
              "duration_ms",
              "created_at",
              "variants",
              "urls_expire_at",
              "demo"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "type": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "duration_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "variants": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Files/$defs/variant"
                }
              },
              "urls_expire_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "demo": {
                "type": "boolean",
                "description": "Seeded demo content of a dev/test account (OC-DEMO-CONTENT); always false for real accounts."
              },
              "derivative": {
                "type": "boolean",
                "description": "Edited capture copy; never evidence of an original signature."
              }
            }
          }
        }
      },
      "UploadIssued": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "UploadIssued",
        "description": "POST /api/v1/files/uploads 201 (IMPL-B2-STORAGE): the upload row and the presigned PUT the browser sends the bytes to (exact Content-Type header and Content-Length are part of the signature; expires in 600 s). Optional client id is an idempotency key. Reissue returns the same upload and a renewed PUT only while issued; put is null after confirmation.",
        "type": "object",
        "required": [
          "upload",
          "put",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "upload": {
            "$ref": "#/components/schemas/UploadIssued/$defs/upload"
          },
          "put": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "method",
                  "url",
                  "headers",
                  "expires_at"
                ],
                "additionalProperties": false,
                "properties": {
                  "method": {
                    "const": "PUT"
                  },
                  "url": {
                    "type": "string"
                  },
                  "headers": {
                    "type": "object",
                    "required": [
                      "Content-Type"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "Content-Type": {
                        "type": "string"
                      }
                    }
                  },
                  "expires_at": {
                    "type": "string",
                    "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        },
        "$defs": {
          "upload": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "name",
              "size",
              "state",
              "error",
              "retryable",
              "file_id",
              "created_at"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "state": {
                "enum": [
                  "issued",
                  "uploaded",
                  "processing",
                  "ready",
                  "failed",
                  "expired",
                  "deleted"
                ]
              },
              "error": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Failure code when state is failed: type_mismatch, size_mismatch, unsupported, corrupt, too_many_pixels, too_long (final) or processing_failed, encoder_missing, encoder_failed, transcode_failed, timeout, storage_unavailable (retryable)."
              },
              "retryable": {
                "type": "boolean"
              },
              "file_id": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              }
            }
          },
          "variant": {
            "type": "object",
            "required": [
              "variant",
              "format",
              "mime",
              "size",
              "width",
              "height",
              "url"
            ],
            "additionalProperties": false,
            "properties": {
              "variant": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,16}$"
              },
              "format": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,8}$"
              },
              "mime": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 0
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "url": {
                "type": "string",
                "description": "Presigned GET (SigV4 query, X-Amz-Expires <= B2_SIGNED_URL_TTL, max 3600 s) on the private bucket; never a permanent URL."
              }
            }
          },
          "file": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "type",
              "name",
              "size",
              "width",
              "height",
              "duration_ms",
              "created_at",
              "variants",
              "urls_expire_at",
              "demo"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "type": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "duration_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "variants": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/UploadIssued/$defs/variant"
                }
              },
              "urls_expire_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "demo": {
                "type": "boolean",
                "description": "Seeded demo content of a dev/test account (OC-DEMO-CONTENT); always false for real accounts."
              },
              "derivative": {
                "type": "boolean",
                "description": "Edited capture copy; never evidence of an original signature."
              }
            }
          }
        }
      },
      "Upload": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Upload",
        "description": "GET /api/v1/files/uploads/{id} 200, POST .../complete|retry 202/200 (IMPL-B2-STORAGE).",
        "type": "object",
        "required": [
          "upload",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "upload": {
            "$ref": "#/components/schemas/Upload/$defs/upload"
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        },
        "$defs": {
          "upload": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "name",
              "size",
              "state",
              "error",
              "retryable",
              "file_id",
              "created_at"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "state": {
                "enum": [
                  "issued",
                  "uploaded",
                  "processing",
                  "ready",
                  "failed",
                  "expired",
                  "deleted"
                ]
              },
              "error": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Failure code when state is failed: type_mismatch, size_mismatch, unsupported, corrupt, too_many_pixels, too_long (final) or processing_failed, encoder_missing, encoder_failed, transcode_failed, timeout, storage_unavailable (retryable)."
              },
              "retryable": {
                "type": "boolean"
              },
              "file_id": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              }
            }
          },
          "variant": {
            "type": "object",
            "required": [
              "variant",
              "format",
              "mime",
              "size",
              "width",
              "height",
              "url"
            ],
            "additionalProperties": false,
            "properties": {
              "variant": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,16}$"
              },
              "format": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,8}$"
              },
              "mime": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 0
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "url": {
                "type": "string",
                "description": "Presigned GET (SigV4 query, X-Amz-Expires <= B2_SIGNED_URL_TTL, max 3600 s) on the private bucket; never a permanent URL."
              }
            }
          },
          "file": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "type",
              "name",
              "size",
              "width",
              "height",
              "duration_ms",
              "created_at",
              "variants",
              "urls_expire_at",
              "demo"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "type": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "duration_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "variants": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Upload/$defs/variant"
                }
              },
              "urls_expire_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "demo": {
                "type": "boolean",
                "description": "Seeded demo content of a dev/test account (OC-DEMO-CONTENT); always false for real accounts."
              },
              "derivative": {
                "type": "boolean",
                "description": "Edited capture copy; never evidence of an original signature."
              }
            }
          }
        }
      },
      "File": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "File",
        "description": "GET /api/v1/files/{id} 200 (IMPL-B2-STORAGE): one own ready file with fresh signed URLs.",
        "type": "object",
        "required": [
          "file",
          "ttl",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "file": {
            "$ref": "#/components/schemas/File/$defs/file"
          },
          "ttl": {
            "type": "integer",
            "minimum": 60,
            "maximum": 3600
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        },
        "$defs": {
          "upload": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "name",
              "size",
              "state",
              "error",
              "retryable",
              "file_id",
              "created_at"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "name": {
                "type": "string",
                "minLength": 1,
                "maxLength": 200
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "state": {
                "enum": [
                  "issued",
                  "uploaded",
                  "processing",
                  "ready",
                  "failed",
                  "expired",
                  "deleted"
                ]
              },
              "error": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Failure code when state is failed: type_mismatch, size_mismatch, unsupported, corrupt, too_many_pixels, too_long (final) or processing_failed, encoder_missing, encoder_failed, transcode_failed, timeout, storage_unavailable (retryable)."
              },
              "retryable": {
                "type": "boolean"
              },
              "file_id": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              }
            }
          },
          "variant": {
            "type": "object",
            "required": [
              "variant",
              "format",
              "mime",
              "size",
              "width",
              "height",
              "url"
            ],
            "additionalProperties": false,
            "properties": {
              "variant": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,16}$"
              },
              "format": {
                "type": "string",
                "pattern": "^[a-z0-9]{1,8}$"
              },
              "mime": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 0
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "url": {
                "type": "string",
                "description": "Presigned GET (SigV4 query, X-Amz-Expires <= B2_SIGNED_URL_TTL, max 3600 s) on the private bucket; never a permanent URL."
              }
            }
          },
          "file": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "type",
              "name",
              "size",
              "width",
              "height",
              "duration_ms",
              "created_at",
              "variants",
              "urls_expire_at",
              "demo"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "image",
                  "video",
                  "document"
                ]
              },
              "type": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "size": {
                "type": "integer",
                "minimum": 1
              },
              "width": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "height": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "duration_ms": {
                "type": [
                  "integer",
                  "null"
                ],
                "minimum": 0
              },
              "created_at": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "variants": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/File/$defs/variant"
                }
              },
              "urls_expire_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
              },
              "demo": {
                "type": "boolean",
                "description": "Seeded demo content of a dev/test account (OC-DEMO-CONTENT); always false for real accounts."
              },
              "derivative": {
                "type": "boolean",
                "description": "Edited capture copy; never evidence of an original signature."
              }
            }
          }
        }
      },
      "Contexts": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Areas",
        "description": "GET /api/v1/contexts 200 body (OC-009): active areas of the current workspace, default first. The default area has name null (the UI shows its localised label).",
        "type": "object",
        "required": [
          "contexts",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "contexts": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "id",
                "kind",
                "default",
                "name",
                "version",
                "archived"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
                },
                "kind": {
                  "enum": [
                    "personal",
                    "household",
                    "business",
                    "other"
                  ]
                },
                "default": {
                  "type": "boolean"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "maxLength": 60
                },
                "version": {
                  "type": "integer",
                  "minimum": 1
                },
                "archived": {
                  "type": "boolean"
                }
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Context": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Area",
        "description": "GET/PATCH /api/v1/contexts/{id} 200, POST /api/v1/contexts 201/200 body (OC-009).",
        "type": "object",
        "required": [
          "context",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "context": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "default",
              "name",
              "version",
              "archived"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "enum": [
                  "personal",
                  "household",
                  "business",
                  "other"
                ]
              },
              "default": {
                "type": "boolean"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 60
              },
              "version": {
                "type": "integer",
                "minimum": 1
              },
              "archived": {
                "type": "boolean"
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Job": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Job",
        "description": "GET /api/v1/jobs/{id} and POST /api/v1/jobs/{id}/cancel 200 body (OC-070, IMPL-011). status is what the person sees; held/waiting is never done; eta is null unless measured.",
        "type": "object",
        "required": [
          "job",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "job": {
            "$ref": "#/components/schemas/Job/$defs/job"
          },
          "request_id": {
            "type": "string"
          }
        },
        "$defs": {
          "job": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "lane",
              "status",
              "state",
              "reason",
              "attempts",
              "cancel",
              "created_at",
              "updated_at",
              "finished_at",
              "eta"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "type": "string",
                "pattern": "^[a-z][a-z_]{1,30}\\.[a-z][a-z_]{1,40}$"
              },
              "lane": {
                "enum": [
                  "normal",
                  "auth",
                  "tasks",
                  "connector",
                  "extraction",
                  "maintenance"
                ]
              },
              "status": {
                "enum": [
                  "waiting",
                  "running",
                  "held",
                  "needs_you",
                  "done",
                  "cancelled",
                  "failed"
                ]
              },
              "state": {
                "enum": [
                  "queued",
                  "running",
                  "waiting_limit",
                  "waiting_user",
                  "blocked",
                  "done",
                  "cancelled",
                  "failed",
                  "dead"
                ]
              },
              "reason": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[a-z][a-z0-9_]{1,63}$"
              },
              "attempts": {
                "type": "integer"
              },
              "cancel": {
                "enum": [
                  "available",
                  "requested",
                  null
                ]
              },
              "created_at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "updated_at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "finished_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "eta": {
                "$ref": "#/components/schemas/Job/$defs/eta"
              }
            }
          },
          "eta": {
            "type": [
              "object",
              "null"
            ],
            "required": [
              "seconds",
              "basis",
              "samples",
              "window_seconds",
              "lower_seconds",
              "upper_seconds"
            ],
            "additionalProperties": false,
            "properties": {
              "seconds": {
                "type": "integer"
              },
              "basis": {
                "const": "observed"
              },
              "samples": {
                "type": "integer"
              },
              "window_seconds": {
                "type": "integer"
              },
              "lower_seconds": {
                "type": "integer",
                "minimum": 1
              },
              "upper_seconds": {
                "type": "integer",
                "minimum": 1
              }
            }
          }
        }
      },
      "QueueStatus": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Queue status",
        "description": "GET /api/v1/queue/status 200 body (OC-070, IMPL-011): the signed-in member's unfinished jobs per lane.",
        "type": "object",
        "required": [
          "queue",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "queue": {
            "type": "object",
            "required": [
              "lanes",
              "jobs"
            ],
            "additionalProperties": false,
            "properties": {
              "lanes": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/QueueStatus/$defs/lane"
                }
              },
              "jobs": {
                "type": "array",
                "maxItems": 20,
                "items": {
                  "$ref": "#/components/schemas/QueueStatus/$defs/job"
                }
              }
            }
          },
          "request_id": {
            "type": "string"
          }
        },
        "$defs": {
          "lane": {
            "type": "object",
            "required": [
              "lane",
              "waiting",
              "running",
              "held",
              "needs_you",
              "reasons",
              "eta"
            ],
            "additionalProperties": false,
            "properties": {
              "lane": {
                "enum": [
                  "normal",
                  "auth",
                  "tasks",
                  "connector",
                  "extraction",
                  "maintenance"
                ]
              },
              "waiting": {
                "type": "integer"
              },
              "running": {
                "type": "integer"
              },
              "held": {
                "type": "integer"
              },
              "needs_you": {
                "type": "integer"
              },
              "reasons": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{1,63}$"
                }
              },
              "eta": {
                "$ref": "#/components/schemas/QueueStatus/$defs/eta"
              }
            }
          },
          "eta": {
            "type": [
              "object",
              "null"
            ],
            "required": [
              "seconds",
              "basis",
              "samples",
              "window_seconds",
              "lower_seconds",
              "upper_seconds"
            ],
            "additionalProperties": false,
            "properties": {
              "seconds": {
                "type": "integer"
              },
              "basis": {
                "const": "observed"
              },
              "samples": {
                "type": "integer"
              },
              "window_seconds": {
                "type": "integer"
              },
              "lower_seconds": {
                "type": "integer",
                "minimum": 1
              },
              "upper_seconds": {
                "type": "integer",
                "minimum": 1
              }
            }
          },
          "job": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "lane",
              "status",
              "state",
              "reason",
              "attempts",
              "cancel",
              "created_at",
              "updated_at",
              "finished_at",
              "eta"
            ],
            "additionalProperties": false,
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
              },
              "kind": {
                "type": "string",
                "pattern": "^[a-z][a-z_]{1,30}\\.[a-z][a-z_]{1,40}$"
              },
              "lane": {
                "enum": [
                  "normal",
                  "auth",
                  "tasks",
                  "connector",
                  "extraction",
                  "maintenance"
                ]
              },
              "status": {
                "enum": [
                  "waiting",
                  "running",
                  "held",
                  "needs_you",
                  "done",
                  "cancelled",
                  "failed"
                ]
              },
              "state": {
                "enum": [
                  "queued",
                  "running",
                  "waiting_limit",
                  "waiting_user",
                  "blocked",
                  "done",
                  "cancelled",
                  "failed",
                  "dead"
                ]
              },
              "reason": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[a-z][a-z0-9_]{1,63}$"
              },
              "attempts": {
                "type": "integer"
              },
              "cancel": {
                "enum": [
                  "available",
                  "requested",
                  null
                ]
              },
              "created_at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "updated_at": {
                "type": "string",
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "finished_at": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
              },
              "eta": {
                "$ref": "#/components/schemas/QueueStatus/$defs/eta"
              }
            }
          }
        }
      },
      "Search": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Search",
        "description": "POST scoped lexical search. Tasks and areas only; unintegrated indexes stay explicitly not searched. Signed continuation is bound to the current snapshot, query, filter and member.",
        "type": "object",
        "required": [
          "search",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "search": {
            "type": "object",
            "required": [
              "groups",
              "count",
              "partial",
              "searched",
              "not_searched"
            ],
            "additionalProperties": false,
            "properties": {
              "groups": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "type",
                    "items"
                  ],
                  "additionalProperties": false,
                  "properties": {
                    "type": {
                      "enum": [
                        "areas",
                        "tasks"
                      ]
                    },
                    "items": {
                      "type": "array",
                      "maxItems": 20,
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "kind",
                          "name"
                        ],
                        "additionalProperties": false,
                        "properties": {
                          "id": {
                            "type": "string",
                            "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
                          },
                          "kind": {
                            "enum": [
                              "personal",
                              "household",
                              "business",
                              "other",
                              "task"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "maxLength": 12000
                          },
                          "type": {
                            "enum": [
                              "areas",
                              "tasks"
                            ]
                          },
                          "revision": {
                            "type": "integer",
                            "minimum": 1
                          },
                          "command_revision": {
                            "type": "integer",
                            "minimum": 1
                          }
                        }
                      }
                    }
                  }
                }
              },
              "count": {
                "type": "integer",
                "minimum": 0
              },
              "partial": {
                "type": "boolean"
              },
              "searched": {
                "type": "array",
                "items": {
                  "enum": [
                    "areas",
                    "tasks"
                  ]
                }
              },
              "not_searched": {
                "type": "array",
                "items": {
                  "enum": [
                    "messages",
                    "events",
                    "files",
                    "people"
                  ]
                }
              },
              "facets": {
                "type": "object",
                "required": [
                  "areas",
                  "tasks"
                ],
                "additionalProperties": false,
                "properties": {
                  "areas": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "tasks": {
                    "type": "integer",
                    "minimum": 0
                  }
                }
              },
              "count_is_partial": {
                "type": "boolean"
              },
              "next_cursor": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 512
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Theme": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "Theme",
        "description": "GET/PATCH /api/v1/preferences/theme 200 body (OC-075): system follows the device.",
        "type": "object",
        "required": [
          "theme",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "theme": {
            "type": "object",
            "required": [
              "theme",
              "version"
            ],
            "additionalProperties": false,
            "properties": {
              "theme": {
                "enum": [
                  "system",
                  "light",
                  "dark"
                ]
              },
              "version": {
                "type": "integer",
                "minimum": 0
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Members": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "MemberList",
        "description": "GET /api/v1/workspaces/{id}/members (OC-003). Membership ids only; never global user ids or profile data.",
        "type": "object",
        "required": [
          "members",
          "request_id"
        ],
        "additionalProperties": false,
        "properties": {
          "members": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "role",
                "state",
                "self"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
                },
                "role": {
                  "enum": [
                    "owner",
                    "admin",
                    "member",
                    "viewer"
                  ]
                },
                "state": {
                  "enum": [
                    "active",
                    "invited"
                  ]
                },
                "self": {
                  "type": "boolean"
                }
              }
            }
          },
          "request_id": {
            "type": "string",
            "pattern": "^req_[0-9a-f]{24}$"
          }
        }
      },
      "Rentals": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "title": "GET /api/v1/rentals (OC-ARRENDAMENTO)",
        "type": "object",
        "required": [
          "rentals",
          "request_id"
        ],
        "properties": {
          "request_id": {
            "type": "string"
          },
          "rentals": {
            "type": "object",
            "required": [
              "consent",
              "capabilities"
            ],
            "properties": {
              "consent": {
                "type": "object",
                "required": [
                  "version",
                  "accepted",
                  "accepted_at"
                ],
                "properties": {
                  "version": {
                    "type": "string"
                  },
                  "accepted": {
                    "type": "boolean"
                  },
                  "accepted_at": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              },
              "capabilities": {
                "type": "object",
                "required": [
                  "drive",
                  "at",
                  "bank",
                  "statements",
                  "extraction"
                ]
              },
              "today": {
                "type": "string"
              },
              "properties": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "version",
                    "demo"
                  ]
                }
              },
              "lessees": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "name",
                    "ibans",
                    "version",
                    "demo"
                  ]
                }
              },
              "contracts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "property_id",
                    "lessee_ids",
                    "start_date",
                    "rent_cents",
                    "periodicity",
                    "due_day",
                    "state",
                    "original",
                    "version"
                  ]
                }
              },
              "rents": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "contract_id",
                    "period",
                    "due_date",
                    "amount_cents",
                    "paid_cents",
                    "remaining_cents",
                    "state",
                    "late"
                  ],
                  "properties": {
                    "state": {
                      "enum": [
                        "due",
                        "late",
                        "partial",
                        "paid",
                        "forgiven"
                      ]
                    }
                  }
                }
              },
              "transactions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "source",
                    "booked_on",
                    "amount_cents",
                    "match_state",
                    "payments"
                  ],
                  "properties": {
                    "match_state": {
                      "enum": [
                        "unmatched",
                        "suggested",
                        "matched",
                        "ignored"
                      ]
                    }
                  }
                }
              },
              "receipts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "id",
                    "period",
                    "kind",
                    "amount_cents",
                    "state",
                    "source"
                  ],
                  "properties": {
                    "state": {
                      "enum": [
                        "imported",
                        "prepared",
                        "issued",
                        "cancelled"
                      ]
                    }
                  }
                }
              },
              "imports": {
                "type": "array"
              },
              "bank_links": {
                "type": "array"
              },
              "at": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "nif": {
                    "type": "string",
                    "pattern": "[0-9]{3}$"
                  }
                }
              },
              "drive": {
                "type": [
                  "object",
                  "null"
                ]
              },
              "overview": {
                "type": "object",
                "required": [
                  "month",
                  "expected_cents",
                  "received_cents",
                  "due_cents",
                  "late_cents",
                  "late_count"
                ]
              },
              "pending": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "kind",
                    "id"
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}
