{
  "openapi": "3.1.0",
  "info": {
    "title": "Weekkeep Agent API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://weekkeep.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "agentToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Weekkeep scoped token"
      },
      "feedBasic": {
        "type": "http",
        "scheme": "basic",
        "description": "Username weekkeep, password the full scoped token. RSS only."
      }
    }
  },
  "paths": {
    "/api/agent/journal": {
      "get": {
        "summary": "Read cloud journal, revision and sync epoch.",
        "description": "Required scope: journal:read",
        "security": [
          {
            "agentToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Missing scope"
          },
          "409": {
            "description": "Stale revision/epoch or paused sync"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/api/agent/events": {
      "post": {
        "summary": "Apply one validated event; requires current revision and epoch.",
        "description": "Required scope: journal:write",
        "security": [
          {
            "agentToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Missing scope"
          },
          "409": {
            "description": "Stale revision/epoch or paused sync"
          },
          "429": {
            "description": "Rate limited"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "revision",
                  "epoch",
                  "event"
                ],
                "properties": {
                  "revision": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "epoch": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "event": {
                    "type": "object",
                    "required": [
                      "type"
                    ],
                    "properties": {
                      "type": {
                        "enum": [
                          "SAVE_ENTRY",
                          "DELETE_ENTRY",
                          "SAVE_COMPASS",
                          "TOGGLE_LIVED",
                          "CLOSE_WEEK",
                          "REOPEN_WEEK",
                          "ACKNOWLEDGE"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/agent/feed.rss": {
      "get": {
        "summary": "Private RSS 2.0, latest 50 memories; supports Bearer or Basic (username weekkeep).",
        "description": "Required scope: feed:read",
        "security": [
          {
            "agentToken": []
          },
          {
            "feedBasic": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/rss+xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Missing scope"
          },
          "409": {
            "description": "Stale revision/epoch or paused sync"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    }
  },
  "externalDocs": {
    "url": "https://weekkeep.com/agent-api.md",
    "description": "Event fields, authentication, concurrency and error handling"
  }
}
