{
  "openapi": "3.1.0",
  "info": {
    "title": "Okae API",
    "version": "1.0.0",
    "description": "Manage repository configuration and inspect or request assessments as a GitHub organisation owner."
  },
  "servers": [
    {
      "url": "https://app.okae.ai",
      "description": "Okae API"
    }
  ],
  "security": [
    {
      "apiSession": []
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "Authorise a workspace, inspect a session and revoke access."
    },
    {
      "name": "Workspace"
    },
    {
      "name": "Repositories"
    },
    {
      "name": "Configuration"
    },
    {
      "name": "Assessments"
    }
  ],
  "paths": {
    "/api/v1/workspace/status": {
      "get": {
        "tags": ["Workspace"],
        "operationId": "getWorkspaceStatus",
        "x-docs-order": 1,
        "summary": "Get workspace status",
        "description": "Check available and reserved credits, processing state and the number of connected repositories visible to the owner. The session selects the workspace.",
        "responses": {
          "200": {
            "description": "Status of the workspace authorised for this session.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["workspace", "service_state", "processing_enabled", "connected_repositories", "credits"],
                  "properties": {
                    "workspace": {
                      "$ref": "#/components/schemas/SessionInfo/properties/workspace"
                    },
                    "service_state": {
                      "type": "string",
                      "enum": ["active", "inactive", "credits_required"]
                    },
                    "processing_enabled": {
                      "type": "boolean"
                    },
                    "connected_repositories": {
                      "type": "integer",
                      "minimum": 0
                    },
                    "credits": {
                      "type": "object",
                      "required": ["available", "reserved"],
                      "properties": {
                        "available": {
                          "type": "number",
                          "description": "Credits currently available to spend."
                        },
                        "reserved": {
                          "type": "number",
                          "description": "Credits held for assessments in progress."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "workspace": {
                    "id": "befd47ea-81e8-4413-9684-54493256f63c",
                    "name": "octo-example"
                  },
                  "service_state": "active",
                  "processing_enabled": true,
                  "connected_repositories": 3,
                  "credits": {
                    "available": 98,
                    "reserved": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/auth/authorize": {
      "get": {
        "tags": ["Authentication"],
        "operationId": "authorizeSession",
        "x-docs-order": 1,
        "summary": "Authorise an API session",
        "description": "Open this URL in the system browser. The owner signs in through GitHub and grants access to configure one workspace and read or request assessments. The client verifies the returned state. Only registered loopback callback shapes are accepted. Browser consent uses the existing session and CSRF protections.",
        "security": [],
        "parameters": [
          {
            "name": "redirect_uri",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Loopback callback at http://127.0.0.1:{ephemeral-port}/callback. The exchange must use the exact same URI.",
              "format": "uri",
              "example": "http://127.0.0.1:51342/callback"
            },
            "description": "Client loopback callback."
          },
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unpredictable client-generated value."
            },
            "description": "Correlates the login with the local client."
          },
          {
            "name": "code_challenge",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Base64url-encoded SHA-256 digest of the verifier.",
              "pattern": "^[A-Za-z0-9_-]{43}$"
            },
            "description": "PKCE challenge."
          },
          {
            "name": "code_challenge_method",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["S256"]
            },
            "description": "Required challenge method."
          }
        ],
        "responses": {
          "200": {
            "description": "GitHub sign-in, onboarding or owner consent page.",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "302": {
            "description": "Open the Okae authorisation page. Signed-out owners select Continue with GitHub to sign in. After consent, the browser returns to the validated loopback callback with code and state, or error=access_denied and state on cancellation.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/auth/token": {
      "post": {
        "tags": ["Authentication"],
        "operationId": "exchangeAuthorizationCode",
        "x-docs-order": 2,
        "summary": "Exchange the authorisation code",
        "description": "A native client exchanges a single-use, five-minute code bound to its PKCE challenge, callback URI, owner and workspace. Store the credential securely and send it as `Authorization: Bearer <token>` on API requests.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "grant_type": {
                    "type": "string",
                    "enum": ["authorization_code"]
                  },
                  "code": {
                    "type": "string",
                    "description": "Single-use authorisation code."
                  },
                  "redirect_uri": {
                    "type": "string",
                    "description": "Loopback callback at http://127.0.0.1:{ephemeral-port}/callback. The exchange must use the exact same URI.",
                    "format": "uri",
                    "example": "http://127.0.0.1:51342/callback"
                  },
                  "code_verifier": {
                    "type": "string",
                    "description": "Original PKCE verifier.",
                    "minLength": 43,
                    "maxLength": 128,
                    "pattern": "^[A-Za-z0-9._~-]+$"
                  }
                },
                "required": ["grant_type", "code", "redirect_uri", "code_verifier"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Seven-day workspace credential. No refresh token is issued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionToken"
                },
                "example": {
                  "access_token": "<store-in-keychain>",
                  "token_type": "Bearer",
                  "expires_in": 604800,
                  "workspace_id": "befd47ea-81e8-4413-9684-54493256f63c"
                }
              }
            },
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "enum": ["no-store"]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/auth/session": {
      "get": {
        "tags": ["Authentication"],
        "operationId": "getSession",
        "x-docs-order": 3,
        "summary": "Show the current API session",
        "description": "Returns session identity, workspace and expiry without querying GitHub. Repository operations verify live authority separately.",
        "responses": {
          "200": {
            "description": "Current API session.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionInfo"
                },
                "example": {
                  "user": {
                    "id": "c6d39605-0b59-4761-8f57-d69c3911dde5",
                    "login": "octo-owner",
                    "display_name": "Octo Owner"
                  },
                  "workspace": {
                    "id": "befd47ea-81e8-4413-9684-54493256f63c",
                    "name": "octo-example"
                  },
                  "expires_at": "2026-11-17T10:00:00Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/auth/revoke": {
      "post": {
        "tags": ["Authentication"],
        "operationId": "revokeSession",
        "x-docs-order": 4,
        "summary": "Revoke the current API session",
        "description": "Invalidate the bearer credential used for this request. Owners can also revoke sessions through the dashboard.",
        "responses": {
          "204": {
            "description": "Session revoked."
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories": {
      "get": {
        "tags": ["Repositories"],
        "operationId": "listRepositories",
        "x-docs-order": 2,
        "summary": "List connected repositories",
        "description": "Lists only repositories visible to the current owner in the session workspace. Totals use the same access and search filters.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            },
            "description": "Number of matching rows to skip."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "description": "Maximum rows returned."
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Case-insensitive search text."
          },
          {
            "name": "repository_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "responses": {
          "200": {
            "description": "List connected repositories",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepositoryPage"
                },
                "example": {
                  "repositories": [
                    {
                      "id": "b24a126b-76a2-46e4-ae08-95477789565f",
                      "name": "inventory",
                      "full_name": "example/inventory",
                      "private": true,
                      "default_branch": "main",
                      "processing_enabled": true
                    }
                  ],
                  "total": 1,
                  "synced_at": "2026-11-10T08:00:00Z"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/repository-context": {
      "get": {
        "tags": ["Repositories"],
        "operationId": "getRepositoryContext",
        "x-docs-order": 1,
        "summary": "Resolve repository setup status",
        "description": "Find a repository in the signed-in workspace by its Git remote. When the repository cannot be identified in scope, return the same generic setup action as for an unknown repository. No name, binding, or assessment from another workspace is revealed. Unsupported hosts are rejected without a request to that host. A failed provider read is an error.",
        "parameters": [
          {
            "name": "remote",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "example": "https://github.com/example/inventory"
            },
            "description": "Canonical GitHub repository URL derived from the selected remote or --repo."
          }
        ],
        "responses": {
          "200": {
            "description": "Resolve repository setup status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepositoryContext"
                },
                "example": {
                  "workspace_id": "63d66c0c-6cd9-428d-ae50-03344c0086fe",
                  "repository": {
                    "id": "b24a126b-76a2-46e4-ae08-95477789565f",
                    "full_name": "example/inventory"
                  },
                  "status": "ready",
                  "mode": "shadow",
                  "next_action_url": null,
                  "latest_assessment": null
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories/{repository_id}/settings": {
      "get": {
        "tags": ["Configuration"],
        "operationId": "getSettings",
        "x-docs-order": 1,
        "summary": "Read effective configuration",
        "description": "Returns the default-branch policy and its sources. Missing okae.yml inherits defaults. An invalid file produces configuration errors. File-controlled fields must be changed in the repository.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "responses": {
          "200": {
            "description": "Read effective configuration",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Settings"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "put": {
        "tags": ["Configuration"],
        "operationId": "applySettings",
        "x-docs-order": 4,
        "summary": "Apply a configuration change",
        "description": "Save only an owner-approved draft. A stale revision returns 409 settings_changed: read and preview again. If the response is lost, read the current revision and values before retrying. Saving settings does not start an assessment.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SettingsDraft"
              },
              "example": {
                "expected_revision": 7,
                "updates": {
                  "enabled_rules": {
                    "lockfiles": false
                  }
                },
                "removals": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Apply a configuration change",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Settings"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories/{repository_id}/settings/preview": {
      "post": {
        "tags": ["Configuration"],
        "operationId": "previewSettings",
        "x-docs-order": 2,
        "summary": "Preview a configuration change",
        "description": "Compare the current effective policy with the proposed policy without saving or spending credits. A valid draft can still have field errors; inspect can_save before applying.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SettingsDraft"
              },
              "example": {
                "expected_revision": 7,
                "updates": {
                  "enabled_rules": {
                    "lockfiles": false
                  }
                },
                "removals": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Preview a configuration change",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SettingsPreview"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories/{repository_id}/settings/file-preview": {
      "post": {
        "tags": ["Configuration"],
        "operationId": "previewSettingsFile",
        "x-docs-order": 3,
        "summary": "Preview okae.yml",
        "description": "Compare the current default-branch policy with the supplied okae.yml and existing managed overrides. Send null to preview deleting the file. The base commit identifies the configuration being compared. The proposed file has no published URL or blob SHA. Errors describe invalid settings. Previewing does not change the repository or workspace.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["content"],
                "additionalProperties": false,
                "properties": {
                  "content": {
                    "description": "Proposed UTF-8 contents, up to 64 KiB. Use null for deletion.",
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 65536
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              },
              "example": {
                "content": "assess_drafts: true\n"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Effective settings before and after applying the proposed file contents. Changes include fields with a different value or source.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SettingsPreview"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories/{repository_id}/pull-requests": {
      "get": {
        "tags": ["Assessments"],
        "operationId": "listOpenPullRequests",
        "x-docs-order": 0,
        "summary": "List open pull requests",
        "description": "Choose an open pull request in the authorised repository. A provider failure returns an error.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "responses": {
          "200": {
            "description": "Open pull requests available to assess.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["pull_requests", "first_assessment"],
                  "properties": {
                    "pull_requests": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/OpenPullRequest"
                      }
                    },
                    "first_assessment": {
                      "type": "object",
                      "properties": {
                        "assessment": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "url": {
                                  "type": "string",
                                  "format": "uri"
                                },
                                "outcome": {
                                  "type": "string",
                                  "enum": ["approve", "review"]
                                },
                                "approval_submitted": {
                                  "type": "boolean"
                                },
                                "pull_request": {
                                  "type": "object",
                                  "properties": {
                                    "number": {
                                      "type": "integer",
                                      "minimum": 1
                                    },
                                    "title": {
                                      "type": "string"
                                    },
                                    "url": {
                                      "type": "string",
                                      "format": "uri"
                                    }
                                  },
                                  "required": ["number", "title", "url"]
                                },
                                "summary": {
                                  "type": "string"
                                }
                              },
                              "required": ["url", "outcome", "approval_submitted", "pull_request", "summary"]
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "required": ["assessment"]
                    }
                  }
                },
                "example": {
                  "pull_requests": [
                    {
                      "number": 42,
                      "title": "Add inventory search",
                      "url": "https://github.com/example/inventory/pull/42",
                      "head_sha": "b10aee0f983af246eb1fc96a76d32dae14289e52",
                      "base_branch": "main"
                    }
                  ],
                  "first_assessment": {
                    "assessment": null
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories/{repository_id}/pull-requests/{number}/check": {
      "post": {
        "tags": ["Assessments"],
        "operationId": "runAssessment",
        "x-docs-order": 2,
        "summary": "Request an assessment",
        "description": "Queue an assessment of the open PR. Okae verifies the repository and pins the current GitHub head revision at submission. The response includes that SHA and the job_id to poll. If supplied, head_sha must match the current head. An active run returns a conflict.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          },
          {
            "in": "path",
            "name": "number",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "PR number in this repository."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RunAssessmentRequest"
              },
              "example": {}
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted. Use job_id to watch this work.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcceptedAssessment"
                },
                "example": {
                  "job_id": "64d5124c-2e89-4c78-8e18-5d461a48a048",
                  "pull_request": {
                    "number": 42,
                    "title": "Add inventory search",
                    "url": "https://github.com/example/inventory/pull/42",
                    "head_sha": "b10aee0f983af246eb1fc96a76d32dae14289e52",
                    "base_branch": "main"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/checks": {
      "get": {
        "tags": ["Assessments"],
        "operationId": "listAssessments",
        "x-docs-order": 4,
        "summary": "List assessments",
        "description": "List runs newest first. Supply repository_id to filter by repository. A workspace list uses the same visibility restrictions on rows and totals. Use the returned assessment ID to inspect one run.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "name": "repository_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          },
          {
            "name": "pull_request_number",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "Filter by repository-scoped PR number."
          },
          {
            "name": "head_sha",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{40}$"
            },
            "description": "Filter by exact revision."
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            },
            "description": "Number of matching rows to skip."
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            },
            "description": "Maximum rows returned."
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Case-insensitive search text."
          },
          {
            "name": "outcome",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["all", "approve", "review", "error", "pending", "waiting", "superseded"],
              "default": "all"
            },
            "description": "Filter by result."
          },
          {
            "name": "date_from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Inclusive UTC start date."
          },
          {
            "name": "date_to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Inclusive UTC end date; maximum span 366 days."
          },
          {
            "name": "latest_per_pr",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Use the latest published Approve or Review for each PR within the period."
          }
        ],
        "responses": {
          "200": {
            "description": "List assessments",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AssessmentPage"
                },
                "example": {
                  "checks": [
                    {
                      "id": "64d5124c-2e89-4c78-8e18-5d461a48a048",
                      "title": "Add inventory search",
                      "target": {
                        "kind": "pr",
                        "number": 42,
                        "url": "https://github.com/example/inventory/pull/42",
                        "head_sha": "b10aee0f983af246eb1fc96a76d32dae14289e52"
                      },
                      "status": "completed",
                      "outcome": "review",
                      "reasons": ["Protected path", "Dependency manifest"],
                      "approval_mode": "shadow",
                      "approval_submitted": false,
                      "created_at": "2026-11-10T08:00:00Z",
                      "completed_at": "2026-11-10T08:00:05Z",
                      "published_at": "2026-11-10T08:00:06Z",
                      "check_url": "https://github.com/example/inventory/runs/12345",
                      "repository": {
                        "id": "b24a126b-76a2-46e4-ae08-95477789565f",
                        "full_name": "example/inventory"
                      }
                    }
                  ],
                  "total": 1
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/checks/{check_id}": {
      "get": {
        "tags": ["Assessments"],
        "operationId": "getAssessment",
        "x-docs-order": 3,
        "summary": "Inspect an assessment",
        "description": "Return one exact run under the same repository visibility as history. Poll this resource until a published judgement or terminal unassessed state. Honour Retry-After on 429. Cancelling a local wait does not cancel work.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "check_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Assessment ID returned by list or run."
          }
        ],
        "responses": {
          "200": {
            "description": "Inspect an assessment",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Assessment"
                },
                "example": {
                  "id": "64d5124c-2e89-4c78-8e18-5d461a48a048",
                  "title": "Add inventory search",
                  "target": {
                    "kind": "pr",
                    "number": 42,
                    "url": "https://github.com/example/inventory/pull/42",
                    "head_sha": "b10aee0f983af246eb1fc96a76d32dae14289e52"
                  },
                  "status": "completed",
                  "outcome": "review",
                  "reasons": ["Protected path", "Dependency manifest"],
                  "approval_mode": "shadow",
                  "approval_submitted": false,
                  "created_at": "2026-11-10T08:00:00Z",
                  "completed_at": "2026-11-10T08:00:05Z",
                  "published_at": "2026-11-10T08:00:06Z",
                  "check_url": "https://github.com/example/inventory/runs/12345",
                  "repository": {
                    "id": "b24a126b-76a2-46e4-ae08-95477789565f",
                    "full_name": "example/inventory"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/v1/workspaces/{workspace_id}/repositories/{repository_id}/preflight": {
      "post": {
        "tags": ["Configuration"],
        "operationId": "runPreflight",
        "x-docs-order": 5,
        "summary": "Run a preflight on changes",
        "description": "Apply the repository's rule checks to change metadata before you open a pull request. Send paths, renames, line counts and Git modes only, never file contents. The default-branch okae.yml and managed settings supply the policy. A preflight is free: it creates no assessment and uses no credits. A clean result doesn't predict approval, because the full assessment also reviews the diff.",
        "parameters": [
          {
            "in": "path",
            "name": "workspace_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae workspace ID from this session."
          },
          {
            "in": "path",
            "name": "repository_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Okae repository UUID returned as repository.id, or as id on a repository list item."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PreflightRequest"
              },
              "example": {
                "files": [
                  {
                    "path": "src/app.ts",
                    "status": "modified",
                    "additions": 12,
                    "deletions": 3,
                    "binary": false,
                    "old_mode": "100644",
                    "new_mode": "100644"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rule results for the supplied changes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preflight"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiSession": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Opaque API session",
        "description": "Owner credential for a single workspace. Expires after seven days or on revocation."
      }
    },
    "schemas": {
      "SessionInfo": {
        "type": "object",
        "properties": {
          "user": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "login": {
                "type": "string",
                "description": "GitHub login."
              },
              "display_name": {
                "type": ["string", "null"],
                "description": "Display name on the linked GitHub account."
              }
            },
            "required": ["id", "login", "display_name"]
          },
          "workspace": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string",
                "description": "Workspace display name."
              }
            },
            "required": ["id", "name"]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": ["user", "workspace", "expires_at"]
      },
      "SessionToken": {
        "type": "object",
        "properties": {
          "access_token": {
            "type": "string",
            "description": "Secret returned once."
          },
          "token_type": {
            "type": "string",
            "enum": ["Bearer"]
          },
          "expires_in": {
            "type": "integer",
            "const": 604800
          },
          "workspace_id": {
            "type": "string",
            "format": "uuid"
          }
        },
        "required": ["access_token", "token_type", "expires_in", "workspace_id"]
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable error code."
              },
              "message": {
                "type": "string",
                "description": "Human-readable error."
              },
              "request_id": {
                "type": "string"
              },
              "fields": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "string"
                  }
                }
              }
            },
            "required": ["code", "message", "request_id"]
          }
        },
        "required": ["error"]
      },
      "RepositoryIdentity": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Okae repository ID. Use this UUID for the repository_id path or query parameter."
          },
          "full_name": {
            "type": "string"
          }
        },
        "required": ["id", "full_name"]
      },
      "Repository": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Okae repository ID. Use this UUID for the repository_id path or query parameter."
          },
          "name": {
            "type": "string"
          },
          "full_name": {
            "type": "string"
          },
          "private": {
            "type": "boolean"
          },
          "default_branch": {
            "type": "string"
          },
          "processing_enabled": {
            "type": "boolean"
          }
        },
        "required": ["id", "name", "full_name", "private", "default_branch", "processing_enabled"]
      },
      "RepositoryPage": {
        "type": "object",
        "properties": {
          "repositories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Repository"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "synced_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": ["repositories", "total", "synced_at"]
      },
      "RepositoryContext": {
        "type": "object",
        "properties": {
          "workspace_id": {
            "type": "string",
            "format": "uuid"
          },
          "repository": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/RepositoryIdentity"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "type": "string",
            "enum": ["ready", "setup_required"]
          },
          "mode": {
            "anyOf": [
              {
                "type": "string",
                "enum": ["shadow", "automatic"]
              },
              {
                "type": "null"
              }
            ]
          },
          "next_action_url": {
            "anyOf": [
              {
                "type": "string",
                "format": "uri"
              },
              {
                "type": "null"
              }
            ]
          },
          "latest_assessment": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri"
                  }
                },
                "required": ["id", "url"]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": ["workspace_id", "repository", "status", "mode", "next_action_url", "latest_assessment"]
      },
      "SettingOverrides": {
        "type": "object",
        "properties": {
          "enable_approvals": {
            "type": "boolean",
            "description": "Allow automatic approvals. Obtain explicit owner agreement before enabling."
          },
          "assess_drafts": {
            "type": "boolean"
          },
          "assess_forks": {
            "type": "boolean",
            "description": "Assess PRs opened from forks. Only repository settings can set it; an okae.yml that sets it is invalid."
          },
          "strictness": {
            "type": "string",
            "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive"]
          },
          "protected_paths": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Repository-relative globs."
          },
          "ignored_paths": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Repository-relative globs excluded from size limits, file checks and the assessed diff. Must not overlap protected paths."
          },
          "max_changed_lines": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2000
          },
          "max_files": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "enabled_rules": {
            "type": "object",
            "properties": {
              "deleted_files": {
                "type": "boolean"
              },
              "renamed_files": {
                "type": "boolean"
              },
              "ci_configuration": {
                "type": "boolean"
              },
              "dependency_manifests": {
                "type": "boolean"
              },
              "lockfiles": {
                "type": "boolean"
              },
              "licence_files": {
                "type": "boolean"
              },
              "code_ownership": {
                "type": "boolean"
              },
              "infrastructure": {
                "type": "boolean"
              },
              "api_schemas": {
                "type": "boolean"
              },
              "database_migrations": {
                "type": "boolean"
              },
              "binary_files": {
                "type": "boolean"
              },
              "executable_permissions": {
                "type": "boolean"
              },
              "symlinks": {
                "type": "boolean"
              },
              "submodules": {
                "type": "boolean"
              },
              "agent_instructions": {
                "type": "boolean"
              },
              "hidden_characters": {
                "type": "boolean"
              },
              "auto_run_config": {
                "type": "boolean"
              }
            },
            "additionalProperties": false
          },
          "signals": {
            "type": "object",
            "description": "Strictness, or Off, for individual signals. Omit a signal to inherit strictness. Security signals use danger_off; Okae doesn't recommend disabling them.",
            "properties": {
              "consumer_compatibility": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "data_access": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "permissions": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "production": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "dependencies": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "hard_to_revert": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "entry_point": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "weakens_verification": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "off"]
              },
              "memory_safety": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "danger_off"]
              },
              "injection": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "danger_off"]
              },
              "unsafe_deserialization": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "danger_off"]
              },
              "security_controls": {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "danger_off"]
              }
            },
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      },
      "SettingKey": {
        "type": "string",
        "enum": [
          "enable_approvals",
          "assess_drafts",
          "assess_forks",
          "strictness",
          "protected_paths",
          "ignored_paths",
          "max_changed_lines",
          "max_files",
          "enabled_rules.deleted_files",
          "enabled_rules.renamed_files",
          "enabled_rules.ci_configuration",
          "enabled_rules.dependency_manifests",
          "enabled_rules.lockfiles",
          "enabled_rules.licence_files",
          "enabled_rules.code_ownership",
          "enabled_rules.infrastructure",
          "enabled_rules.api_schemas",
          "enabled_rules.database_migrations",
          "enabled_rules.binary_files",
          "enabled_rules.executable_permissions",
          "enabled_rules.symlinks",
          "enabled_rules.submodules",
          "enabled_rules.agent_instructions",
          "enabled_rules.hidden_characters",
          "enabled_rules.auto_run_config",
          "signals.consumer_compatibility",
          "signals.data_access",
          "signals.permissions",
          "signals.production",
          "signals.dependencies",
          "signals.hard_to_revert",
          "signals.entry_point",
          "signals.weakens_verification",
          "signals.memory_safety",
          "signals.injection",
          "signals.unsafe_deserialization",
          "signals.security_controls"
        ]
      },
      "SettingsDraft": {
        "type": "object",
        "properties": {
          "expected_revision": {
            "anyOf": [
              {
                "type": "integer",
                "minimum": 1
              },
              {
                "type": "null"
              }
            ],
            "description": "The revision read from storage.repository.revision. Null for the first save."
          },
          "updates": {
            "$ref": "#/components/schemas/SettingOverrides"
          },
          "removals": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SettingKey"
            },
            "maxItems": 20,
            "description": "Remove an override to resume inheritance. Omit a key from updates to leave it alone."
          }
        },
        "required": ["expected_revision", "updates", "removals"],
        "additionalProperties": false
      },
      "SettingValue": {
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "boolean"
          },
          {
            "type": "integer"
          },
          {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        ]
      },
      "SettingField": {
        "type": "object",
        "properties": {
          "key": {
            "$ref": "#/components/schemas/SettingKey"
          },
          "value": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/SettingValue"
              },
              {
                "type": "null"
              }
            ]
          },
          "source": {
            "anyOf": [
              {
                "type": "string",
                "enum": ["service_default", "dashboard", "okae_yml", "strictness"]
              },
              {
                "type": "null"
              }
            ]
          },
          "default": {
            "$ref": "#/components/schemas/SettingValue"
          },
          "constraints": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": ["boolean", "integer", "string", "array"]
              },
              "minimum": {
                "type": "integer"
              },
              "maximum": {
                "type": "integer"
              },
              "enum": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "labels": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "items": {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string"
                  }
                },
                "required": ["type"]
              },
              "mandatory": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "read_only": {
                "type": "boolean"
              }
            },
            "required": ["type"]
          }
        },
        "required": ["key", "value", "source", "default", "constraints"]
      },
      "SettingNotice": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "path": {
            "type": "string"
          }
        },
        "required": ["code", "message"]
      },
      "Settings": {
        "type": "object",
        "properties": {
          "workspace_id": {
            "type": "string",
            "format": "uuid"
          },
          "repository": {
            "$ref": "#/components/schemas/RepositoryIdentity"
          },
          "context": {
            "type": "object",
            "properties": {
              "branch": {
                "type": "string"
              },
              "commit_sha": {
                "type": "string",
                "pattern": "^[0-9a-f]{40}$"
              },
              "file": {
                "type": "object",
                "properties": {
                  "path": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": ["present", "missing"]
                  },
                  "blob_sha": {
                    "anyOf": [
                      {
                        "type": "string",
                        "pattern": "^[0-9a-f]{40}$"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "url": {
                    "anyOf": [
                      {
                        "type": "string",
                        "format": "uri"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": ["path", "status", "blob_sha", "url"]
              }
            },
            "required": ["branch", "commit_sha", "file"]
          },
          "configuration": {
            "type": "object",
            "properties": {
              "status": {
                "type": "string",
                "enum": ["valid", "invalid"]
              },
              "errors": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/SettingNotice"
                }
              }
            },
            "required": ["status", "errors"]
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SettingField"
            }
          },
          "review_setting": {
            "anyOf": [
              {
                "type": "string",
                "enum": ["most_cautious", "cautious", "standard", "permissive", "most_permissive", "custom"]
              },
              {
                "type": "null"
              }
            ],
            "description": "The strictness level every signal resolves to, or custom when they differ. Null when the configuration is invalid."
          },
          "approval": {
            "type": "object",
            "properties": {
              "available": {
                "type": "boolean"
              },
              "blockers": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/SettingNotice"
                }
              }
            },
            "required": ["available", "blockers"]
          },
          "warnings": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SettingNotice"
            }
          },
          "storage": {
            "type": "object",
            "properties": {
              "repository": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": ["available"]
                  },
                  "revision": {
                    "anyOf": [
                      {
                        "type": "integer",
                        "minimum": 1
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "overrides": {
                    "$ref": "#/components/schemas/SettingOverrides"
                  }
                },
                "required": ["status", "revision", "overrides"]
              }
            },
            "required": ["repository"]
          }
        },
        "required": [
          "workspace_id",
          "repository",
          "context",
          "configuration",
          "fields",
          "review_setting",
          "approval",
          "warnings",
          "storage"
        ]
      },
      "SettingsPreview": {
        "type": "object",
        "properties": {
          "before": {
            "$ref": "#/components/schemas/Settings"
          },
          "after": {
            "$ref": "#/components/schemas/Settings"
          },
          "changes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "key": {
                  "$ref": "#/components/schemas/SettingKey"
                }
              },
              "required": ["key"]
            }
          },
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SettingNotice"
            }
          },
          "can_save": {
            "type": "boolean"
          }
        },
        "required": ["before", "after", "changes", "errors", "can_save"]
      },
      "PrTarget": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": ["pr"]
          },
          "number": {
            "type": "integer",
            "minimum": 1
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "head_sha": {
            "type": "string",
            "pattern": "^[0-9a-f]{40}$"
          }
        },
        "required": ["kind", "number", "url", "head_sha"]
      },
      "OpenPullRequest": {
        "type": "object",
        "properties": {
          "number": {
            "type": "integer",
            "minimum": 1
          },
          "title": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "head_sha": {
            "type": "string",
            "pattern": "^[0-9a-f]{40}$"
          },
          "base_branch": {
            "type": "string"
          }
        },
        "required": ["number", "title", "url", "head_sha", "base_branch"]
      },
      "RunAssessmentRequest": {
        "type": "object",
        "properties": {
          "head_sha": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-9a-f]{40}$"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "additionalProperties": false
      },
      "AcceptedAssessment": {
        "type": "object",
        "properties": {
          "job_id": {
            "type": "string",
            "format": "uuid",
            "description": "Durable ID for assessments show and polling."
          },
          "pull_request": {
            "$ref": "#/components/schemas/OpenPullRequest"
          }
        },
        "required": ["job_id", "pull_request"]
      },
      "Assessment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "repository": {
            "$ref": "#/components/schemas/RepositoryIdentity"
          },
          "title": {
            "type": "string"
          },
          "target": {
            "$ref": "#/components/schemas/PrTarget"
          },
          "status": {
            "type": "string",
            "enum": ["queued", "running", "retrying", "completed", "failed", "superseded"]
          },
          "outcome": {
            "type": "string",
            "enum": ["approve", "review", "error", "pending", "waiting", "superseded"],
            "description": "Approve and Review are successful published judgements. Waiting, error and superseded explain unassessed terminal runs; pending covers work awaiting publication."
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Recorded customer-facing reasons for this assessment or its processing status. An empty list means no reason is available."
          },
          "approval_mode": {
            "anyOf": [
              {
                "type": "string",
                "enum": ["shadow", "automatic"]
              },
              {
                "type": "null"
              }
            ]
          },
          "approval_submitted": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "assessed_at": {
            "description": "When the assessment result was recorded, before publication.",
            "type": ["string", "null"],
            "format": "date-time"
          },
          "completed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "published_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "check_url": {
            "anyOf": [
              {
                "type": "string",
                "format": "uri"
              },
              {
                "type": "null"
              }
            ]
          },
          "author": {
            "type": "string"
          },
          "head_branch": {
            "type": "string"
          },
          "base_branch": {
            "type": "string"
          },
          "author_name": {
            "type": ["string", "null"]
          }
        },
        "required": [
          "id",
          "repository",
          "title",
          "target",
          "status",
          "outcome",
          "reasons",
          "approval_mode",
          "approval_submitted",
          "created_at",
          "completed_at",
          "published_at",
          "check_url"
        ]
      },
      "AssessmentPage": {
        "type": "object",
        "properties": {
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Assessment"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": ["checks", "total"]
      },
      "ChangedFile": {
        "type": "object",
        "required": ["path", "status", "additions", "deletions"],
        "additionalProperties": false,
        "properties": {
          "path": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096,
            "description": "Repository-relative path after the change."
          },
          "previous_path": {
            "anyOf": [
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 4096
              },
              {
                "type": "null"
              }
            ],
            "description": "Path before a rename or copy."
          },
          "status": {
            "type": "string",
            "enum": ["added", "modified", "removed", "renamed", "copied", "changed"]
          },
          "additions": {
            "type": "integer",
            "minimum": 0
          },
          "deletions": {
            "type": "integer",
            "minimum": 0
          },
          "binary": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "description": "Whether Git treats the file as binary. Null when unknown."
          },
          "old_mode": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7]{6}$"
              },
              {
                "type": "null"
              }
            ],
            "description": "Git file mode, such as 100644, 100755, 120000 or 000000 for an absent side. Null when unknown."
          },
          "new_mode": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-7]{6}$"
              },
              {
                "type": "null"
              }
            ],
            "description": "Git file mode, such as 100644, 100755, 120000 or 000000 for an absent side. Null when unknown."
          }
        }
      },
      "PreflightRequest": {
        "type": "object",
        "required": ["files"],
        "additionalProperties": false,
        "properties": {
          "files": {
            "type": "array",
            "minItems": 1,
            "maxItems": 3000,
            "items": {
              "$ref": "#/components/schemas/ChangedFile"
            }
          }
        }
      },
      "Preflight": {
        "type": "object",
        "required": ["repository", "context", "decision", "configuration_error", "rules", "checks"],
        "properties": {
          "repository": {
            "$ref": "#/components/schemas/RepositoryIdentity"
          },
          "context": {
            "type": "object",
            "required": ["branch", "commit_sha"],
            "description": "Default-branch commit whose okae.yml supplied the policy.",
            "properties": {
              "branch": {
                "type": "string"
              },
              "commit_sha": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          },
          "decision": {
            "type": "string",
            "enum": ["review", "no_rule_matched"],
            "description": "review when a rule means the pull request needs human review. no_rule_matched leaves the decision to the full assessment."
          },
          "configuration_error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "description": "Why the repository configuration is invalid. Every pull request needs human review until it is fixed."
          },
          "rules": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Rule IDs that mean the pull request needs human review, including protected for protected paths."
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["rule_id", "state", "action", "evidence"],
              "properties": {
                "rule_id": {
                  "type": "string"
                },
                "state": {
                  "type": "string",
                  "enum": ["matched", "not_matched", "unknown", "disabled"]
                },
                "action": {
                  "type": "string",
                  "enum": ["review", "record"]
                },
                "evidence": {
                  "type": "array",
                  "items": {},
                  "description": "Matching paths, or the actual count and limit for size rules."
                }
              }
            }
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid request or authorisation grant.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "The credential is missing, expired or revoked. Sign in again.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Current owner authority or the required agreement is missing.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "NotFound": {
        "description": "No accessible resource matches the target. Unknown and inaccessible targets have the same response.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Conflict": {
        "description": "The resource changed or this operation conflicts with current state.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "ValidationError": {
        "description": "The request failed validation.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many requests. Wait before retrying.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "error": {
                "code": "rate_limited",
                "message": "Too many requests. Try again shortly.",
                "request_id": "example-request-id"
              }
            }
          }
        },
        "headers": {
          "Retry-After": {
            "required": true,
            "description": "Delay in seconds before retrying.",
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        }
      },
      "Unavailable": {
        "description": "The service or a required provider is unavailable.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    }
  }
}
