{
  "openapi": "3.1.0",
  "info": {
    "title": "Tokenpool",
    "version": "1.0.0"
  },
  "paths": {
    "/v1/config": {
      "get": {
        "summary": "Read config",
        "responses": {
          "200": {
            "description": "JSON result"
          }
        }
      }
    },
    "/v1/projects": {
      "get": {
        "summary": "Read projects",
        "responses": {
          "200": {
            "description": "JSON result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Project"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/tasks": {
      "get": {
        "summary": "Read tasks",
        "responses": {
          "200": {
            "description": "JSON result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Task"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "repository",
                  "scope",
                  "kind",
                  "title",
                  "source"
                ],
                "properties": {
                  "repository": {
                    "type": "string",
                    "minLength": 1
                  },
                  "scope": {
                    "type": "string",
                    "minLength": 1
                  },
                  "kind": {
                    "type": "string",
                    "minLength": 1
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1
                  },
                  "source": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/reports": {
      "get": {
        "summary": "Read reports",
        "responses": {
          "200": {
            "description": "JSON result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Report"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "summary": "Read me",
        "responses": {
          "200": {
            "description": "JSON result"
          }
        }
      }
    },
    "/v1/rankings": {
      "get": {
        "summary": "Read rankings",
        "responses": {
          "200": {
            "description": "JSON result"
          }
        }
      }
    },
    "/v1/claim": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "task",
                  "request_id",
                  "phase"
                ],
                "properties": {
                  "task": {
                    "type": "string",
                    "minLength": 1
                  },
                  "request_id": {
                    "type": "string",
                    "minLength": 1
                  },
                  "phase": {
                    "type": "string",
                    "enum": [
                      "preparation",
                      "execution"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Claim"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/heartbeat": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "task",
                  "token"
                ],
                "properties": {
                  "task": {
                    "type": "string",
                    "minLength": 1
                  },
                  "token": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/release": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "task",
                  "token",
                  "report"
                ],
                "properties": {
                  "task": {
                    "type": "string",
                    "minLength": 1
                  },
                  "token": {
                    "type": "string",
                    "minLength": 1
                  },
                  "report": {
                    "type": "string",
                    "minLength": 1
                  },
                  "result_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/complete": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "task",
                  "token",
                  "report"
                ],
                "properties": {
                  "task": {
                    "type": "string",
                    "minLength": 1
                  },
                  "token": {
                    "type": "string",
                    "minLength": 1
                  },
                  "report": {
                    "type": "string",
                    "minLength": 1
                  },
                  "result_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/pause": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "task",
                  "token",
                  "report"
                ],
                "properties": {
                  "task": {
                    "type": "string",
                    "minLength": 1
                  },
                  "token": {
                    "type": "string",
                    "minLength": 1
                  },
                  "report": {
                    "type": "string",
                    "minLength": 1
                  },
                  "result_url": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/credentials": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/credentials/revoke": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/auth/github-token": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/session": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/logout": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/admin/sync": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [],
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/admin/projects": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "projects",
                  "repositories",
                  "failures"
                ],
                "properties": {
                  "projects": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/Project"
                    }
                  },
                  "repositories": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "failures": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "repository",
                        "error"
                      ],
                      "properties": {
                        "repository": {
                          "type": "string"
                        },
                        "error": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid credential"
          },
          "403": {
            "description": "Cross-origin request"
          },
          "404": {
            "description": "Unknown resource"
          },
          "409": {
            "description": "Conflict or stale proof"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/v1/preferences": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "repositories",
                  "topics",
                  "minutes",
                  "public"
                ],
                "properties": {
                  "repositories": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "topics": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "minutes": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 480
                  },
                  "public": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved preferences"
          },
          "400": {
            "description": "Invalid preferences"
          }
        }
      }
    },
    "/v1/prepare": {
      "post": {
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "task",
                  "token",
                  "proposal"
                ],
                "properties": {
                  "task": {
                    "type": "string"
                  },
                  "token": {
                    "type": "string"
                  },
                  "proposal": {
                    "$ref": "#/components/schemas/Proposal"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Prepared and released; execution can be claimed"
          },
          "400": {
            "description": "Invalid proposal"
          },
          "409": {
            "description": "Wrong phase, stale claim or conflicting retry"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Platform credential; auth/github-token instead takes a GitHub identity token"
      }
    },
    "schemas": {
      "Project": {
        "type": "object",
        "required": [
          "repository",
          "name",
          "description",
          "topics",
          "commit_sha",
          "instructions",
          "instructions_path",
          "enabled"
        ],
        "properties": {
          "repository": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "commit_sha": {
            "type": "string"
          },
          "instructions": {
            "type": "string"
          },
          "instructions_path": {
            "type": "string"
          },
          "topics": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "enabled": {
            "type": [
              "integer",
              "boolean"
            ]
          },
          "checked": {
            "type": "integer"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Claim": {
        "type": "object",
        "required": [
          "task",
          "token",
          "expires",
          "instructions",
          "commit_sha"
        ],
        "properties": {
          "task": {
            "type": "string"
          },
          "token": {
            "type": "string"
          },
          "instructions": {
            "type": "string"
          },
          "commit_sha": {
            "type": "string"
          },
          "expires": {
            "type": "integer"
          },
          "phase": {
            "type": "string",
            "enum": [
              "preparation",
              "execution"
            ]
          },
          "proposal": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Proposal"
              },
              {
                "type": "null"
              }
            ]
          },
          "allowed_tools": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "kind": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "source": {
            "type": "string"
          },
          "scope": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "instructions": {
            "type": [
              "string",
              "null"
            ]
          },
          "instructions_path": {
            "type": "string"
          },
          "commit_sha": {
            "type": "string"
          },
          "donor": {
            "type": [
              "string",
              "null"
            ]
          },
          "expires": {
            "type": [
              "integer",
              "null"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "phase": {
            "type": "string",
            "enum": [
              "preparation",
              "execution"
            ]
          },
          "proposal": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/Proposal"
              },
              {
                "type": "null"
              }
            ]
          },
          "proposal_commit": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "task": {
            "type": "string"
          },
          "outcome": {
            "type": "string"
          },
          "report": {
            "type": "string"
          },
          "repository": {
            "type": "string"
          },
          "donor": {
            "type": "string"
          },
          "result_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "created": {
            "type": "integer"
          }
        }
      },
      "Proposal": {
        "type": "object",
        "required": [
          "objective",
          "approach",
          "workflow",
          "acceptance_criteria",
          "boundaries",
          "sources",
          "risk_notes",
          "required_capabilities"
        ],
        "properties": {
          "objective": {
            "type": "string",
            "minLength": 1
          },
          "approach": {
            "type": "string",
            "minLength": 1
          },
          "workflow": {
            "type": "string",
            "minLength": 1
          },
          "acceptance_criteria": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "boundaries": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "sources": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "risk_notes": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 0
          },
          "required_capabilities": {
            "type": "array",
            "maxItems": 30,
            "items": {
              "type": "string",
              "enum": [
                "read_repository",
                "run_code",
                "write_code",
                "publish_comment",
                "open_pull_request",
                "merge"
              ]
            },
            "minItems": 1
          }
        }
      }
    }
  }
}
