{
  "openapi": "3.0.4",
  "info": {
    "title": "SeenWhatWhen API",
    "version": "1.0.0",
    "description": "A private append-only collection of dated observations for humans and agents. Use HTTP Basic over external HTTPS; Traefik terminates TLS while Go serves HTTP internally. Accounts/password hashes are maintained manually in SQLite; there is no registration API. Observer is independent of account ownership. Start with listFacts and follow next_url; fetch individual details for UTC submission timestamps. To write, send one JSON object to createFact. 201 means created; 409 means no new entry was created and identifies an existing fact or successor. After an uncertain submission, verify existing content AND chain relationship. Current stale/invalid status is global, independent of search filters. Observer/statement limits are 100 Unicode code points after edge trimming. No location/context field exists. All paths are relative to the document's host."
  },
  "servers": [
    {
      "url": "/",
      "description": "Same origin; external HTTPS in production."
    }
  ],
  "security": [
    {
      "basicAuth": []
    },
    {
      "browserSession": []
    },
    {
      "developmentSession": []
    }
  ],
  "paths": {
    "/openapi.json": {
      "get": {
        "operationId": "getOpenAPI",
        "summary": "Discover the API contract",
        "description": "Public, self-contained JSON document with synthetic examples; no private account or collection data.",
        "security": [],
        "responses": {
          "200": {
            "description": "This OpenAPI document.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAPIDocument"
                }
              }
            }
          },
          "414": {
            "description": "URL exceeds application limit.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "head": {
        "operationId": "headGetOpenAPI",
        "summary": "Headers only: Discover the API contract",
        "description": "Equivalent status and headers to GET, with no body. Public, self-contained JSON document with synthetic examples; no private account or collection data.",
        "security": [],
        "responses": {
          "200": {
            "description": "This OpenAPI document."
          },
          "414": {
            "description": "URL exceeds application limit."
          }
        }
      }
    },
    "/api/facts": {
      "get": {
        "operationId": "listFacts",
        "summary": "Search this account's observations",
        "description": "At most 10 observations, descending numeric ID. Defaults: excludes invalid, includes stale. No semantic sorting. Unknown query parameters and repeated scalars are errors. Follow next_url to preserve filters. New inserts do not shift older cursor pages, but status is live, not a historical snapshot. submitted_at is omitted.",
        "parameters": [
          {
            "$ref": "#/components/parameters/All"
          },
          {
            "$ref": "#/components/parameters/Any"
          },
          {
            "$ref": "#/components/parameters/From"
          },
          {
            "$ref": "#/components/parameters/To"
          },
          {
            "$ref": "#/components/parameters/IncludeInvalid"
          },
          {
            "$ref": "#/components/parameters/IncludeStale"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "Bounded observation list.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createFact",
        "summary": "Append an observation, correction, update, or tombstone",
        "description": "Strictly append-only; no edit/delete endpoints. Accounts have independent F1–F9999999 IDs. Ownership comes from authentication; observer is self-reported. Observation date has no API default and cannot be future-dated using fixed UTC-5. Chains are linear; only the final ordinary fact can be extended. Updates cannot predate their target. Tombstones close the chain. Exact observer/date/statement duplicates are permanently forbidden, even for stale/invalid facts. A retry returns 409 with existing ID/URL/status, never successful creation. No client idempotency key. Strings are trimmed only at edges before 100-code-point limits and case-sensitive uniqueness. Cookie-authenticated writes also require the matching CSRF token. Do not combine Basic credentials and a session cookie.",
        "security": [
          {
            "basicAuth": []
          },
          {
            "browserSession": [],
            "csrfToken": []
          },
          {
            "developmentSession": [],
            "csrfToken": []
          }
        ],
        "requestBody": {
          "required": true,
          "description": "At most 16,384 bytes; all field values are strings.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInput"
              },
              "examples": {
                "new": {
                  "summary": "Independent observation",
                  "value": {
                    "observation_date": "2026-12-01",
                    "observer": "Inventory Agent",
                    "statement": "We own 15 computers."
                  }
                },
                "update": {
                  "summary": "Changed circumstances; predecessor becomes stale",
                  "value": {
                    "action": "update",
                    "target_id": "F1",
                    "observation_date": "2026-12-02",
                    "observer": "Inventory Agent",
                    "statement": "We own 16 computers."
                  }
                },
                "correction": {
                  "summary": "Earlier observation was wrong",
                  "value": {
                    "action": "correction",
                    "target_id": "F1",
                    "observation_date": "2026-12-01",
                    "observer": "Human Reviewer",
                    "statement": "We own 14 computers."
                  }
                },
                "tombstone": {
                  "summary": "Invalidation without replacement",
                  "value": {
                    "action": "tombstone",
                    "target_id": "F1",
                    "observer": "Human Reviewer"
                  }
                },
                "prefilled": {
                  "summary": "Similar independent observation; no chain relationship retained",
                  "value": {
                    "copy_from_id": "F1",
                    "observation_date": "2026-12-01",
                    "observer": "Inventory Agent",
                    "statement": "We own 15 laptops."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "New immutable entry, including UTC submitted_at.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FactDetail"
                }
              }
            },
            "headers": {
              "Location": {
                "description": "API URL of the created fact.",
                "required": true,
                "schema": {
                  "type": "string",
                  "pattern": "^/api/facts/F[1-9][0-9]{0,6}$"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "413": {
            "$ref": "#/components/responses/BodyTooLarge"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMediaType"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "head": {
        "operationId": "headListFacts",
        "summary": "Headers only: Search this account's observations",
        "description": "Equivalent status and headers to GET, with no body. At most 10 observations, descending numeric ID. Defaults: excludes invalid, includes stale. No semantic sorting. Unknown query parameters and repeated scalars are errors. Follow next_url to preserve filters. New inserts do not shift older cursor pages, but status is live, not a historical snapshot. submitted_at is omitted.",
        "parameters": [
          {
            "$ref": "#/components/parameters/All"
          },
          {
            "$ref": "#/components/parameters/Any"
          },
          {
            "$ref": "#/components/parameters/From"
          },
          {
            "$ref": "#/components/parameters/To"
          },
          {
            "$ref": "#/components/parameters/IncludeInvalid"
          },
          {
            "$ref": "#/components/parameters/IncludeStale"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "Bounded observation list."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/facts/{id}": {
      "get": {
        "operationId": "getFact",
        "summary": "Read one fact's complete details",
        "description": "Includes second-precision UTC submitted_at. Stale/invalid status remains visible even if a successor would not match a search. Tombstones are addressable. Links in response data refer to human-readable /facts/ID; use /api/facts/ID for JSON. Only the authenticated account is searched.",
        "parameters": [
          {
            "$ref": "#/components/parameters/FactID"
          }
        ],
        "responses": {
          "200": {
            "description": "Complete observation or tombstone.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FactDetail"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "head": {
        "operationId": "headGetFact",
        "summary": "Headers only: Read one fact's complete details",
        "description": "Equivalent status and headers to GET, with no body. Includes second-precision UTC submitted_at. Stale/invalid status remains visible even if a successor would not match a search. Tombstones are addressable. Links in response data refer to human-readable /facts/ID; use /api/facts/ID for JSON. Only the authenticated account is searched.",
        "parameters": [
          {
            "$ref": "#/components/parameters/FactID"
          }
        ],
        "responses": {
          "200": {
            "description": "Complete observation or tombstone."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/api/facts/{id}/history": {
      "get": {
        "operationId": "getFactHistory",
        "summary": "Read the whole chain in bounded pages",
        "description": "Works from root, middle, or tombstone. Newest numeric ID first, at most 10 entries, including tombstones. submitted_at is omitted. Only before is accepted; no search/date/status filtering. Status comes from the full account, not the page. Follow next_url until absent.",
        "parameters": [
          {
            "$ref": "#/components/parameters/FactID"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "Bounded chain history including tombstones.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Page"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "head": {
        "operationId": "headGetFactHistory",
        "summary": "Headers only: Read the whole chain in bounded pages",
        "description": "Equivalent status and headers to GET, with no body. Works from root, middle, or tombstone. Newest numeric ID first, at most 10 entries, including tombstones. submitted_at is omitted. Only before is accepted; no search/date/status filtering. Status comes from the full account, not the page. Follow next_url until absent.",
        "parameters": [
          {
            "$ref": "#/components/parameters/FactID"
          },
          {
            "$ref": "#/components/parameters/Before"
          }
        ],
        "responses": {
          "200": {
            "description": "Bounded chain history including tombstones."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowed"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "414": {
            "$ref": "#/components/responses/URLTooLong"
          },
          "422": {
            "$ref": "#/components/responses/ValidationFailed"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "FactID": {
        "type": "string",
        "pattern": "^F[1-9][0-9]{0,6}$",
        "example": "F1"
      },
      "Date": {
        "type": "string",
        "format": "date",
        "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
        "example": "2026-12-01"
      },
      "FactURL": {
        "type": "string",
        "pattern": "^/facts/F[1-9][0-9]{0,6}$",
        "example": "/facts/F1"
      },
      "FactFields": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "observer",
          "statement",
          "action",
          "status",
          "url"
        ],
        "description": "Immutable observation fields. Status is computed from the immediate successor across the whole account. Invalidating a successor never restores an older entry.",
        "properties": {
          "id": {
            "$ref": "#/components/schemas/FactID"
          },
          "kind": {
            "type": "string",
            "enum": [
              "observation",
              "tombstone"
            ]
          },
          "observation_date": {
            "$ref": "#/components/schemas/Date"
          },
          "observer": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "statement": {
            "type": "string",
            "maxLength": 100
          },
          "submitted_at": {
            "type": "string",
            "format": "date-time",
            "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$",
            "description": "Second-precision UTC; details and newly-created entries only."
          },
          "action": {
            "type": "string",
            "enum": [
              "new",
              "update",
              "correction",
              "tombstone"
            ]
          },
          "predecessor_id": {
            "$ref": "#/components/schemas/FactID"
          },
          "predecessor_url": {
            "$ref": "#/components/schemas/FactURL"
          },
          "status": {
            "type": "string",
            "enum": [
              "current",
              "stale",
              "invalidated",
              "tombstone"
            ]
          },
          "status_explanation": {
            "type": "string",
            "description": "Current status explanation, including when a successor lies outside the selected search/date range."
          },
          "status_date": {
            "$ref": "#/components/schemas/Date"
          },
          "successor_id": {
            "$ref": "#/components/schemas/FactID"
          },
          "successor_url": {
            "$ref": "#/components/schemas/FactURL"
          },
          "url": {
            "$ref": "#/components/schemas/FactURL"
          }
        },
        "oneOf": [
          {
            "required": [
              "observation_date"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "observation"
                ]
              },
              "action": {
                "enum": [
                  "new",
                  "update",
                  "correction"
                ]
              },
              "statement": {
                "minLength": 1
              },
              "status": {
                "enum": [
                  "current",
                  "stale",
                  "invalidated"
                ]
              }
            }
          },
          {
            "required": [
              "predecessor_id",
              "predecessor_url",
              "status_explanation"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "tombstone"
                ]
              },
              "action": {
                "enum": [
                  "tombstone"
                ]
              },
              "statement": {
                "enum": [
                  ""
                ]
              },
              "status": {
                "enum": [
                  "tombstone"
                ]
              }
            },
            "not": {
              "required": [
                "observation_date"
              ]
            }
          }
        ],
        "example": {
          "id": "F1",
          "kind": "observation",
          "observation_date": "2026-12-01",
          "observer": "Inventory Agent",
          "statement": "We own 15 computers.",
          "action": "new",
          "status": "current",
          "url": "/facts/F1"
        }
      },
      "FactDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/FactFields"
          },
          {
            "type": "object",
            "required": [
              "submitted_at"
            ]
          }
        ],
        "description": "Single entry or created-entry response; includes UTC submission timestamp.",
        "example": {
          "id": "F1",
          "kind": "observation",
          "observation_date": "2026-12-01",
          "observer": "Inventory Agent",
          "statement": "We own 15 computers.",
          "action": "new",
          "status": "current",
          "url": "/facts/F1",
          "submitted_at": "2026-12-03T15:04:05Z"
        }
      },
      "FactListItem": {
        "allOf": [
          {
            "$ref": "#/components/schemas/FactFields"
          },
          {
            "not": {
              "required": [
                "submitted_at"
              ]
            }
          }
        ],
        "description": "List/history item; submitted_at is forbidden, not merely optional.",
        "example": {
          "id": "F1",
          "kind": "observation",
          "observation_date": "2026-12-01",
          "observer": "Inventory Agent",
          "statement": "We own 15 computers.",
          "action": "new",
          "status": "current",
          "url": "/facts/F1"
        }
      },
      "Page": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "facts"
        ],
        "properties": {
          "facts": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "$ref": "#/components/schemas/FactListItem"
            }
          },
          "next_before": {
            "$ref": "#/components/schemas/FactID"
          },
          "next_url": {
            "type": "string",
            "pattern": "^/api/facts",
            "description": "Relative API URL preserving filters; follow verbatim. Absent on the last page."
          }
        },
        "oneOf": [
          {
            "required": [
              "next_before",
              "next_url"
            ]
          },
          {
            "not": {
              "anyOf": [
                {
                  "required": [
                    "next_before"
                  ]
                },
                {
                  "required": [
                    "next_url"
                  ]
                }
              ]
            }
          }
        ],
        "example": {
          "facts": [
            {
              "id": "F1",
              "kind": "observation",
              "observation_date": "2026-12-01",
              "observer": "Inventory Agent",
              "statement": "We own 15 computers.",
              "action": "new",
              "status": "current",
              "url": "/facts/F1"
            }
          ]
        }
      },
      "Problem": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Stable machine-readable error code."
          },
          "message": {
            "type": "string",
            "minLength": 1
          },
          "fields": {
            "type": "object",
            "minProperties": 1,
            "additionalProperties": {
              "type": "string"
            }
          },
          "existing_fact_id": {
            "$ref": "#/components/schemas/FactID"
          },
          "existing_fact_url": {
            "$ref": "#/components/schemas/FactURL"
          },
          "existing_fact_status": {
            "type": "string",
            "enum": [
              "current",
              "stale",
              "invalidated",
              "tombstone"
            ]
          },
          "status_explanation": {
            "type": "string"
          },
          "status_date": {
            "$ref": "#/components/schemas/Date"
          },
          "successor_id": {
            "$ref": "#/components/schemas/FactID"
          },
          "successor_url": {
            "$ref": "#/components/schemas/FactURL"
          },
          "relationship_matches": {
            "type": "boolean",
            "description": "For observation duplicates: whether existing action/predecessor matches the attempt. A 409 never means a new operation was applied."
          }
        }
      },
      "OpenAPIDocument": {
        "type": "object",
        "required": [
          "openapi",
          "info",
          "paths"
        ],
        "properties": {
          "openapi": {
            "type": "string",
            "enum": [
              "3.0.4"
            ]
          },
          "info": {
            "type": "object"
          },
          "paths": {
            "type": "object"
          }
        },
        "additionalProperties": true
      },
      "CreateInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "observer"
        ],
        "description": "One JSON object with string values only. Unknown fields, duplicate JSON keys, nulls, invalid UTF-8, and multiple values are rejected. Normalization/date/future/order/uniqueness/chain rules are enforced by the service, including constraints not expressible in JSON Schema.",
        "properties": {
          "observation_date": {
            "type": "string",
            "description": "Observations require YYYY-MM-DD with no API default, not later than today at fixed UTC-5 (no DST). Tombstones omit it or use empty string."
          },
          "observer": {
            "type": "string",
            "minLength": 1,
            "description": "Self-reported name independent of account. After Unicode edge-whitespace trimming: required, at most 100 code points; no NUL/line breaks. The limit applies after trimming, so raw maxLength is not constrained."
          },
          "statement": {
            "type": "string",
            "description": "One factual statement. Ordinary facts require 1–100 Unicode code points after edge trimming; no NUL. Tombstones omit or supply a string empty after trimming. No separate location/context field; include relevant context here."
          },
          "action": {
            "type": "string",
            "enum": [
              "",
              "new",
              "update",
              "correction",
              "tombstone"
            ],
            "default": "new",
            "description": "Omitted or empty means new. Only a chain's final ordinary fact can have a successor."
          },
          "target_id": {
            "type": "string",
            "description": "Target in the current account for update/correction/tombstone. Omitted or empty for independent new observations."
          },
          "copy_from_id": {
            "type": "string",
            "description": "Optional transient source for independent prefilling. Change observer/date/statement from this source; no chain relationship is kept. Omit or empty for chain operations."
          }
        },
        "oneOf": [
          {
            "required": [
              "observation_date",
              "statement"
            ],
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "",
                  "new"
                ]
              },
              "observation_date": {
                "$ref": "#/components/schemas/Date"
              },
              "statement": {
                "type": "string",
                "minLength": 1
              },
              "target_id": {
                "type": "string",
                "enum": [
                  ""
                ]
              },
              "copy_from_id": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/FactID"
                  },
                  {
                    "type": "string",
                    "enum": [
                      ""
                    ]
                  }
                ]
              }
            }
          },
          {
            "required": [
              "action",
              "target_id",
              "observation_date",
              "statement"
            ],
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "update"
                ]
              },
              "target_id": {
                "$ref": "#/components/schemas/FactID"
              },
              "observation_date": {
                "$ref": "#/components/schemas/Date"
              },
              "statement": {
                "type": "string",
                "minLength": 1
              },
              "copy_from_id": {
                "type": "string",
                "enum": [
                  ""
                ]
              }
            }
          },
          {
            "required": [
              "action",
              "target_id",
              "observation_date",
              "statement"
            ],
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "correction"
                ]
              },
              "target_id": {
                "$ref": "#/components/schemas/FactID"
              },
              "observation_date": {
                "$ref": "#/components/schemas/Date"
              },
              "statement": {
                "type": "string",
                "minLength": 1
              },
              "copy_from_id": {
                "type": "string",
                "enum": [
                  ""
                ]
              }
            }
          },
          {
            "required": [
              "action",
              "target_id"
            ],
            "properties": {
              "action": {
                "type": "string",
                "enum": [
                  "tombstone"
                ]
              },
              "target_id": {
                "$ref": "#/components/schemas/FactID"
              },
              "observation_date": {
                "type": "string",
                "enum": [
                  ""
                ]
              },
              "copy_from_id": {
                "type": "string",
                "enum": [
                  ""
                ]
              }
            }
          }
        ]
      }
    },
    "parameters": {
      "FactID": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "Fact ID within the authenticated account.",
        "schema": {
          "$ref": "#/components/schemas/FactID"
        }
      },
      "Before": {
        "name": "before",
        "in": "query",
        "description": "Exclusive fact-ID cursor. Omit/empty to start at the newest entry.",
        "allowEmptyValue": true,
        "schema": {
          "oneOf": [
            {
              "$ref": "#/components/schemas/FactID"
            },
            {
              "type": "string",
              "enum": [
                ""
              ]
            }
          ]
        }
      },
      "All": {
        "name": "all",
        "in": "query",
        "description": "Repeat for every required literal substring. At most 20 nonempty terms of 100 code points each. Empty terms impose no restriction. Unicode case-insensitive; %, _, commas and spaces are literal.",
        "allowEmptyValue": true,
        "style": "form",
        "explode": true,
        "schema": {
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 100
          }
        }
      },
      "Any": {
        "name": "any",
        "in": "query",
        "description": "Repeat alternatives: at least one must match. AND with other groups. At most 20 nonempty terms of 100 code points each.",
        "allowEmptyValue": true,
        "style": "form",
        "explode": true,
        "schema": {
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 100
          }
        }
      },
      "From": {
        "name": "from",
        "in": "query",
        "description": "Inclusive observation-date lower bound. Empty means unbounded.",
        "allowEmptyValue": true,
        "schema": {
          "oneOf": [
            {
              "$ref": "#/components/schemas/Date"
            },
            {
              "type": "string",
              "enum": [
                ""
              ]
            }
          ]
        }
      },
      "To": {
        "name": "to",
        "in": "query",
        "description": "Inclusive observation-date upper bound, not before from. Empty means unbounded.",
        "allowEmptyValue": true,
        "schema": {
          "oneOf": [
            {
              "$ref": "#/components/schemas/Date"
            },
            {
              "type": "string",
              "enum": [
                ""
              ]
            }
          ]
        }
      },
      "IncludeInvalid": {
        "name": "include_invalid",
        "in": "query",
        "description": "Include corrected/invalidated facts; tombstones stay excluded from search lists. Scalars cannot be repeated.",
        "schema": {
          "type": "boolean",
          "default": false
        }
      },
      "IncludeStale": {
        "name": "include_stale",
        "in": "query",
        "description": "Include updated/stale facts. Status is global even if a successor falls outside the date range. Scalars cannot be repeated.",
        "schema": {
          "type": "boolean",
          "default": true
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Malformed request, or Basic credentials combined with a browser session cookie.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "invalid_json",
                        "invalid_body",
                        "invalid_query",
                        "ambiguous_authentication"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing/invalid credentials, expired/revoked session, or account not allowed. No account-enumeration detail.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "authentication_required"
                      ]
                    }
                  }
                }
              ]
            }
          }
        },
        "headers": {
          "WWW-Authenticate": {
            "description": "HTTP Basic challenge.",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^Basic realm="
            }
          }
        }
      },
      "Forbidden": {
        "description": "Missing/invalid cookie-write CSRF token or cross-origin browser write.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "csrf_failed",
                        "cross_origin_request"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource/target/source not found in the current account. Other accounts are never searched.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "not_found"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "MethodNotAllowed": {
        "description": "Unsupported API method.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "method_not_allowed"
                      ]
                    }
                  }
                }
              ]
            }
          }
        },
        "headers": {
          "Allow": {
            "description": "Supported HTTP methods.",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      },
      "Conflict": {
        "description": "No entry created. Duplicates identify existing ID/URL/status and applicable status/relationship metadata. After uncertain writes, retrieve it and verify content AND relationship. Never interpret observation existence alone as proof that a requested correction/update was applied.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "fact_already_exists",
                        "fact_already_has_successor",
                        "chain_closed",
                        "fact_id_limit"
                      ]
                    }
                  },
                  "oneOf": [
                    {
                      "properties": {
                        "error": {
                          "enum": [
                            "fact_already_exists"
                          ]
                        }
                      },
                      "required": [
                        "existing_fact_id",
                        "existing_fact_url",
                        "existing_fact_status"
                      ]
                    },
                    {
                      "properties": {
                        "error": {
                          "enum": [
                            "fact_already_has_successor"
                          ]
                        }
                      },
                      "required": [
                        "existing_fact_id",
                        "existing_fact_url",
                        "existing_fact_status",
                        "successor_id",
                        "successor_url"
                      ]
                    },
                    {
                      "properties": {
                        "error": {
                          "enum": [
                            "chain_closed"
                          ]
                        }
                      },
                      "required": [
                        "existing_fact_id",
                        "existing_fact_url",
                        "existing_fact_status"
                      ]
                    },
                    {
                      "properties": {
                        "error": {
                          "enum": [
                            "fact_id_limit"
                          ]
                        }
                      }
                    }
                  ]
                }
              ]
            }
          }
        }
      },
      "BodyTooLarge": {
        "description": "Body exceeds 16,384 bytes.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "body_too_large"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "URLTooLong": {
        "description": "URL exceeds 8,192 bytes.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "url_too_long"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "UnsupportedMediaType": {
        "description": "API writes require application/json.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "unsupported_media_type"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "ValidationFailed": {
        "description": "Invalid fields/filters; includes fields map. Observations require a nonfuture date at fixed UTC-5; updates cannot predate their predecessor.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "validation_failed"
                      ]
                    }
                  },
                  "required": [
                    "fields"
                  ]
                }
              ]
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Authentication throttled: 20 failures per peer/username per five minutes, bounded buckets, or all four password-check slots busy. Respect Retry-After.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "login_throttled",
                        "authentication_busy"
                      ]
                    }
                  }
                }
              ]
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds before retrying.",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]*$"
            }
          }
        }
      },
      "InternalError": {
        "description": "Request failed; no internal database details are exposed.",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/Problem"
                },
                {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "internal_error"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      }
    },
    "securitySchemes": {
      "basicAuth": {
        "type": "http",
        "scheme": "basic",
        "description": "Recommended for agents: existing account username/password over HTTPS. SEENWHATWHEN_ALLOWED_USERNAMES can further restrict existing accounts."
      },
      "browserSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Host-seenwhatwhen_session",
        "description": "Production browser session from HTML login; HttpOnly/Secure, seven-day absolute lifetime. Restart/logout/account removal/allow-list exclusion/password-hash change revoke access."
      },
      "developmentSession": {
        "type": "apiKey",
        "in": "cookie",
        "name": "seenwhatwhen_session",
        "description": "Local HTTP development only, with SEENWHATWHEN_COOKIE_SECURE=false."
      },
      "csrfToken": {
        "type": "apiKey",
        "in": "header",
        "name": "X-CSRF-Token",
        "description": "Cookie-authenticated writes require the CSRF cookie's value (__Host-seenwhatwhen_csrf; seenwhatwhen_csrf locally). Explicit Basic authentication does not require this token. Browser cross-origin writes are rejected."
      }
    }
  }
}
