{
  "openapi": "3.0.0",
  "info": {
    "title": "BrainGrid API",
    "version": "1.0.0",
    "description": "BrainGrid V1 REST API Documentation - AI-powered code analysis and requirements management",
    "contact": {
      "name": "BrainGrid Team",
      "url": "https://braingrid.ai"
    }
  },
  "servers": [
    {
      "url": "https://api.braingrid.ai",
      "description": "Production"
    },
    {
      "url": "https://app.braingrid.ai/api",
      "description": "Production (app host alias)"
    },
    {
      "url": "https://app.dev.braingrid.ai/api",
      "description": "Development"
    },
    {
      "url": "http://localhost:3000/api",
      "description": "Local"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT token obtained through device flow or WorkOS authentication"
      }
    },
    "responses": {
      "UnauthorizedError": {
        "description": "Unauthorized - missing or invalid authentication token",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "BadRequestError": {
        "description": "Bad request - invalid parameters or request body",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "details": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "NotFoundError": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    },
                    "resource": {
                      "type": "string"
                    },
                    "id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Pagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer",
            "minimum": 1
          },
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "total_pages": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "page",
          "limit",
          "total",
          "total_pages"
        ]
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "number": {
            "type": "string",
            "description": "Task number (e.g., \"1\", \"2\")"
          },
          "title": {
            "type": "string"
          },
          "content": {
            "type": "string",
            "nullable": true,
            "description": "Markdown content describing the task"
          },
          "status": {
            "type": "string",
            "enum": [
              "PLANNED",
              "IN_PROGRESS",
              "COMPLETED",
              "CANCELLED"
            ]
          },
          "complexity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5
          },
          "readiness": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5
          },
          "blocked_by": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Array of task IDs that block this task"
          },
          "started_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "finished_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "requirement": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "title": {
                "type": "string"
              },
              "status": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "title",
              "status"
            ]
          }
        },
        "required": [
          "id",
          "number",
          "title",
          "status",
          "complexity",
          "readiness",
          "blocked_by"
        ]
      },
      "TaskSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "number": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "PLANNED",
              "IN_PROGRESS",
              "COMPLETED",
              "CANCELLED"
            ]
          },
          "started_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "finished_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "number",
          "title",
          "status",
          "updated_at"
        ]
      },
      "RequirementProgress": {
        "type": "object",
        "properties": {
          "requirement_id": {
            "type": "string",
            "format": "uuid"
          },
          "total_tasks": {
            "type": "integer",
            "minimum": 0
          },
          "completed_tasks": {
            "type": "integer",
            "minimum": 0
          },
          "progress_percentage": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "all_tasks_complete": {
            "type": "boolean"
          },
          "remaining_tasks": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "requirement_id",
          "total_tasks",
          "completed_tasks",
          "progress_percentage",
          "all_tasks_complete",
          "remaining_tasks"
        ]
      },
      "Requirement": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "short_id": {
            "type": "string",
            "description": "Human-readable ID (e.g., \"REQ-123\")"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "PLANNED",
              "IN_PROGRESS",
              "COMPLETED",
              "CANCELLED"
            ]
          },
          "complexity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "nullable": true
          },
          "readiness": {
            "type": "integer",
            "minimum": 1,
            "maximum": 5,
            "nullable": true
          },
          "assignee": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "first_name": {
                "type": "string",
                "nullable": true
              },
              "last_name": {
                "type": "string",
                "nullable": true
              },
              "email": {
                "type": "string",
                "format": "email"
              }
            },
            "required": [
              "id",
              "email"
            ]
          },
          "task_progress": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer",
                "minimum": 0
              },
              "completed": {
                "type": "integer",
                "minimum": 0
              },
              "progress_percentage": {
                "type": "number",
                "minimum": 0,
                "maximum": 100
              }
            },
            "required": [
              "total",
              "completed",
              "progress_percentage"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "short_id",
          "name",
          "status",
          "task_progress",
          "created_at",
          "updated_at"
        ]
      },
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "short_id": {
            "type": "string",
            "description": "Human-readable ID (e.g., \"PROJ-123\")"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "repository": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "owner": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "owner",
              "name"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "short_id",
          "name",
          "created_at",
          "updated_at"
        ]
      },
      "Repository": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "owner": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "full_name": {
            "type": "string",
            "description": "Full repository name (e.g., \"owner/repo\")"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "html_url": {
            "type": "string",
            "format": "uri"
          },
          "is_private": {
            "type": "boolean"
          },
          "default_branch": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "owner",
          "name",
          "full_name",
          "html_url",
          "is_private",
          "default_branch",
          "created_at",
          "updated_at"
        ]
      },
      "GitHubInstallation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "short_id": {
            "type": "string",
            "description": "Human-readable ID (e.g., \"INST-123\")"
          },
          "installation_id": {
            "type": "string",
            "description": "GitHub App installation ID"
          },
          "account_name": {
            "type": "string"
          },
          "account_type": {
            "type": "string",
            "enum": [
              "User",
              "Organization"
            ]
          },
          "account_avatar_url": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "installed_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "suspended",
              "removed"
            ]
          },
          "organization": {
            "type": "object",
            "nullable": true,
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "name"
            ]
          },
          "repository_count": {
            "type": "integer",
            "minimum": 0
          }
        },
        "required": [
          "id",
          "short_id",
          "installation_id",
          "account_name",
          "account_type",
          "installed_at",
          "updated_at",
          "status",
          "repository_count"
        ]
      }
    }
  },
  "tags": [
    {
      "name": "Auth",
      "description": "Authentication and authorization endpoints"
    },
    {
      "name": "Profile",
      "description": "User profile management"
    },
    {
      "name": "Projects",
      "description": "Project management operations"
    },
    {
      "name": "Requirements",
      "description": "Requirement management operations"
    },
    {
      "name": "Tasks",
      "description": "Task operations within requirements"
    },
    {
      "name": "Repositories",
      "description": "GitHub repository management"
    },
    {
      "name": "GitHub",
      "description": "GitHub integration endpoints"
    },
    {
      "name": "Review",
      "description": "AI-powered code review services"
    },
    {
      "name": "Agent",
      "description": "AI agent conversation endpoints"
    },
    {
      "name": "GitTokens",
      "description": "Customer-issued tokens for the BrainGrid git proxy"
    }
  ],
  "paths": {
    "/v1/{path}": {
      "get": {
        "summary": "Catch-all for unmatched API v1 paths",
        "description": "Returns a JSON 404 with actionable hints for any unmatched /api/v1/* path. Prevents the HTML not-found page from rendering for API requests.",
        "tags": [
          "System"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "404": {
            "description": "Route not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "hint": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/ai/gateway/models": {
      "get": {
        "summary": "List the models available to this gateway key (plan allowlist)",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "{ data: [{ id, provider }] }"
          },
          "401": {
            "description": "Missing/invalid gateway token"
          }
        }
      }
    },
    "/v1/ai/gateway/v1/messages": {
      "post": {
        "summary": "AI Gateway — Anthropic-shape inference for customer apps",
        "description": "Runtime entrypoint for apps built on BrainGrid. The app's backend\nauthenticates with a per-end-user-session JWT it self-minted using its\nper-project signing key (`Authorization: Bearer <jwt>`). The gateway\nresolves the billing org/project from the key's `kid` (never from a\ntoken claim), honors the requested model against the key's plan\nallowlist, proxies to Bedrock-Anthropic / Vertex-Gemini, and bills the\nORGANIZATION credit account (no membership). Attribution claims ride\ninto the usage event for per-end-user reporting. Errors are\nAnthropic-shaped and carry a `request_id` correlation id.\n",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Success — JSON (non-streaming) or SSE (streaming)"
          },
          "400": {
            "description": "Invalid request / malformed JSON"
          },
          "401": {
            "description": "Missing/invalid gateway token"
          },
          "402": {
            "description": "Org unfunded / out of credits"
          },
          "403": {
            "description": "Org suspended / model not allowed"
          },
          "500": {
            "description": "Unexpected gateway error (carries request_id)"
          }
        }
      }
    },
    "/v1/auth/validate": {
      "post": {
        "summary": "Validate JWT token",
        "description": "Validates JWT tokens for third-party integrations.\nReturns user and organization information for valid tokens.\n",
        "tags": [
          "Auth"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Token validation result",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "valid": {
                          "type": "boolean",
                          "enum": [
                            true
                          ]
                        },
                        "exp": {
                          "type": "integer",
                          "description": "Token expiration timestamp (Unix epoch)"
                        },
                        "user": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "email": {
                              "type": "string",
                              "format": "email"
                            },
                            "username": {
                              "type": "string",
                              "nullable": true
                            },
                            "firstName": {
                              "type": "string",
                              "nullable": true
                            },
                            "lastName": {
                              "type": "string",
                              "nullable": true
                            },
                            "avatar": {
                              "type": "string",
                              "format": "uri",
                              "nullable": true
                            }
                          }
                        },
                        "organization": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "name": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    },
                    {
                      "type": "object",
                      "properties": {
                        "valid": {
                          "type": "boolean",
                          "enum": [
                            false
                          ]
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "validToken": {
                    "value": {
                      "valid": true,
                      "exp": 1704067200,
                      "user": {
                        "id": "user-123",
                        "email": "user@example.com",
                        "username": "johndoe",
                        "firstName": "John",
                        "lastName": "Doe",
                        "avatar": "https://avatar.example.com/user.jpg"
                      },
                      "organization": {
                        "id": "org-456",
                        "name": "Acme Corp"
                      }
                    }
                  },
                  "invalidToken": {
                    "value": {
                      "valid": false
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Service health check",
        "description": "Returns basic information about the validation service",
        "tags": [
          "Auth"
        ],
        "responses": {
          "200": {
            "description": "Service information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "endpoint": {
                      "type": "string"
                    },
                    "methods": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "description": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/domains/{domainId}": {
      "patch": {
        "summary": "Assign, reassign, or unassign an owned domain",
        "description": "Points an owned domain at a project (`project_id`), which sets up DNS for\nthat project automatically, or parks it with `project_id: null`.\nReassigning moves the domain off its previous project first. Owner-only.\n",
        "tags": [
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "domainId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Domain ID (UUID)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "project_id": {
                    "type": "string",
                    "nullable": true,
                    "description": "Project to assign (UUID or PROJ-XXX), or null to unassign"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated domain"
          },
          "400": {
            "description": "Validation failed"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden — only organization owners can manage domains"
          },
          "404": {
            "description": "Domain not found"
          },
          "409": {
            "description": "Target project already has a different custom domain"
          }
        }
      }
    },
    "/v1/domains": {
      "get": {
        "summary": "List the domains owned by the current organization",
        "description": "Returns every domain the organization bought on the platform, newest\nfirst, with its current project assignment (null when parked). Used by\nthe Settings › Domains dashboard. Owner-only.\n",
        "tags": [
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "The organization's domains",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "domains": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden — only organization owners can manage domains"
          }
        }
      }
    },
    "/v1/git-tokens/{id}": {
      "delete": {
        "summary": "Revoke a git token",
        "tags": [
          "GitTokens"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Revoked"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/v1/git-tokens": {
      "get": {
        "summary": "List the caller's git tokens for the current organization",
        "tags": [
          "GitTokens"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Tokens retrieved successfully"
          }
        }
      },
      "post": {
        "summary": "Mint a new git token. The raw token is returned exactly once.",
        "tags": [
          "GitTokens"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "ttl_days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 365
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Token created"
          },
          "422": {
            "description": "Validation failed"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/v1/github/installations/{installationId}": {
      "get": {
        "summary": "Get installation details",
        "description": "Retrieves details for a specific GitHub App installation with repository count",
        "tags": [
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "installationId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Installation retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/GitHubInstallation"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "repositories": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "id": {
                                "type": "string",
                                "format": "uuid"
                              },
                              "full_name": {
                                "type": "string"
                              },
                              "is_private": {
                                "type": "boolean"
                              },
                              "default_branch": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "id": "inst-uuid-1",
                  "short_id": "INST-1",
                  "installation_id": "12345678",
                  "account_name": "braingrid",
                  "account_type": "Organization",
                  "account_avatar_url": "https://avatars.githubusercontent.com/u/123456",
                  "installed_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-20T14:22:00Z",
                  "status": "active",
                  "organization": {
                    "id": "org-uuid",
                    "name": "Acme Corp"
                  },
                  "repository_count": 3,
                  "repositories": [
                    {
                      "id": "repo-uuid-1",
                      "full_name": "braingrid/backend-api",
                      "private": true,
                      "default_branch": "main"
                    },
                    {
                      "id": "repo-uuid-2",
                      "full_name": "braingrid/frontend-app",
                      "private": false,
                      "default_branch": "main"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Installation not found"
          }
        }
      }
    },
    "/v1/github/installations": {
      "get": {
        "summary": "List GitHub installations",
        "description": "Lists all GitHub App installations for the authenticated organization",
        "tags": [
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Installations retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "installations": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/GitHubInstallation"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                },
                "example": {
                  "installations": [
                    {
                      "id": "inst-uuid-1",
                      "short_id": "INST-1",
                      "installation_id": "12345678",
                      "account_name": "braingrid",
                      "account_type": "Organization",
                      "account_avatar_url": "https://avatars.githubusercontent.com/u/123456",
                      "installed_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-20T14:22:00Z",
                      "status": "active",
                      "organization": {
                        "id": "org-uuid",
                        "name": "Acme Corp"
                      },
                      "repository_count": 15
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 50,
                    "total": 3,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "No installations found"
          },
          "422": {
            "description": "Validation error"
          }
        }
      }
    },
    "/v1/oidc/authorize": {
      "get": {
        "summary": "OIDC authorization endpoint — RP entry point",
        "description": "Customer Supabase projects redirect their end users here to start a\nGoogle sign-in. We validate the RP request, encapsulate it in a\nsigned state JWT, and redirect to Google's authorize endpoint with\nour own client_id and a single shared redirect_uri.\n",
        "tags": [
          "OIDC"
        ],
        "parameters": [
          {
            "in": "query",
            "name": "client_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "redirect_uri",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "response_type",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "code"
              ]
            }
          },
          {
            "in": "query",
            "name": "scope",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "state",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "nonce",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "code_challenge",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "code_challenge_method",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "S256"
              ]
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to Google authorize endpoint"
          },
          "400": {
            "description": "Invalid request"
          }
        }
      }
    },
    "/v1/oidc/google/callback": {
      "get": {
        "summary": "Google OAuth callback (single redirect URI for all RPs)",
        "description": "Google redirects users here after consent. We verify the state JWT\n(which carries the original RP context), exchange Google's code,\nverify the id_token, mint our own authorization code, and 302 the\nuser to the RP's redirect_uri.\n",
        "tags": [
          "OIDC"
        ],
        "responses": {
          "302": {
            "description": "Redirect to RP with our authorization code"
          },
          "400": {
            "description": "State validation failed"
          }
        }
      }
    },
    "/v1/oidc/jwks": {
      "get": {
        "summary": "Public JWKS for OIDC id_token verification",
        "description": "Serves the active signing keys (current + previous during rotation\noverlap). Public — no auth required. Customer Supabase projects\ncache this and use it to verify id_tokens we issue.\n",
        "tags": [
          "OIDC"
        ],
        "responses": {
          "200": {
            "description": "JSON Web Key Set",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "keys": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/oidc/token": {
      "post": {
        "summary": "OIDC token endpoint — RP exchanges our auth code for an id_token",
        "description": "Customer Supabase calls this server-to-server with our authorization\ncode (the one we 302'd to its callback) and a PKCE verifier. We\nauthenticate the RP via Basic auth (or form-encoded), verify the\ncode + PKCE + redirect_uri, mint an id_token signed with our\ncurrent key, and return it.\n",
        "tags": [
          "OIDC"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "grant_type",
                  "code",
                  "redirect_uri",
                  "code_verifier"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "id_token + access_token"
          },
          "400": {
            "description": "invalid_grant / invalid_request"
          },
          "401": {
            "description": "invalid_client"
          }
        }
      }
    },
    "/v1/profile": {
      "post": {
        "summary": "Get user profile",
        "description": "Returns user and organization information for authenticated users.\nReturns generic unauthorized response for any authentication failure\nto prevent token probing and exploitation.\n",
        "tags": [
          "Profile"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Profile data",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "user": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "email": {
                              "type": "string",
                              "format": "email"
                            },
                            "username": {
                              "type": "string",
                              "nullable": true
                            },
                            "firstName": {
                              "type": "string",
                              "nullable": true
                            },
                            "lastName": {
                              "type": "string",
                              "nullable": true
                            },
                            "avatar": {
                              "type": "string",
                              "format": "uri",
                              "nullable": true
                            }
                          }
                        },
                        "organization": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "string",
                              "format": "uuid"
                            },
                            "name": {
                              "type": "string"
                            }
                          }
                        },
                        "exp": {
                          "type": "integer",
                          "description": "Token expiration timestamp (Unix epoch)"
                        }
                      }
                    },
                    {
                      "type": "object",
                      "properties": {
                        "error": {
                          "type": "string",
                          "enum": [
                            "Unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                },
                "examples": {
                  "success": {
                    "value": {
                      "user": {
                        "id": "user-123",
                        "email": "user@example.com",
                        "username": "johndoe",
                        "firstName": "John",
                        "lastName": "Doe",
                        "avatar": "https://avatar.example.com/user.jpg"
                      },
                      "organization": {
                        "id": "org-456",
                        "name": "Acme Corp"
                      },
                      "exp": 1704067200
                    }
                  },
                  "unauthorized": {
                    "value": {
                      "error": "Unauthorized"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized (any authentication failure, generic body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "enum": [
                        "Unauthorized"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Service health check",
        "description": "Returns basic information about the profile service",
        "tags": [
          "Profile"
        ],
        "responses": {
          "200": {
            "description": "Service information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "endpoint": {
                      "type": "string"
                    },
                    "methods": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "description": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai-gateway/models": {
      "get": {
        "summary": "Models available through the AI Gateway for a project",
        "description": "The catalog of models a project can call through the gateway — display\nname, provider, context window, and plan gating. Drives the model list\nshown on the dashboard.\n",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Available models"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai-gateway/playground": {
      "post": {
        "summary": "Stream a Playground chat completion through the AI Gateway",
        "description": "Runs real, streamed inference for the dashboard Playground by calling the\nproject's own AI Gateway via `@braingrid/ai-sdk-provider`. The gateway\nresolves org/project from the project key, enforces the plan allowlist,\ndebits credits, and records analytics — so Playground runs appear in the\nAnalytics/Cost/Explorer tabs like any other gateway traffic. Returns an\nAI-SDK UI message stream (consumed client-side by `useChat`).\n",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "UI message stream"
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "AI Gateway not provisioned for this project"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai-gateway/requests/{eventId}": {
      "get": {
        "summary": "Full detail for a single AI Gateway request",
        "description": "Full record for one gateway request — model, billing mode, token + cache\nbreakdown, credits debited + balance after, attribution claims, and (for\nfailures) failure_reason / status_code / error_message.\n",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "eventId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The gateway event id (events.id)."
          }
        ],
        "responses": {
          "200": {
            "description": "Request detail"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or request not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai-gateway/requests": {
      "get": {
        "summary": "Paginated AI Gateway request log for a project",
        "description": "Individual gateway requests (completed + failed) for a project, newest\nfirst. Each row carries model, billing mode, tokens, credits debited,\nend_user_id (attribution), and the upstream request id.\n",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "from",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "in": "query",
            "name": "to",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "completed",
                "failed"
              ],
              "default": "all"
            }
          },
          {
            "in": "query",
            "name": "model",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "billing",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "standard",
                "byok"
              ],
              "default": "all"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated request log"
          },
          "400": {
            "description": "Invalid query parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai-gateway/usage": {
      "get": {
        "summary": "AI Gateway usage analytics & cost for a project",
        "description": "Aggregated AI Gateway metrics for a single project — request volume,\nreliability, token + cache usage, errors, and cost (in CREDITS). BYOK\ntraffic is counted in volume/tokens but bills 0 credits. Breakdowns are\nby model and by billing mode (standard vs BYOK).\n",
        "tags": [
          "AI Gateway"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or PROJ-XXX short id."
          },
          {
            "in": "query",
            "name": "from",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO 8601 start (default 30 days ago)."
          },
          {
            "in": "query",
            "name": "to",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO 8601 end (default now)."
          },
          {
            "in": "query",
            "name": "granularity",
            "schema": {
              "type": "string",
              "enum": [
                "day",
                "week",
                "month"
              ],
              "default": "day"
            }
          },
          {
            "in": "query",
            "name": "model",
            "schema": {
              "type": "string"
            },
            "description": "Restrict to a single model name."
          },
          {
            "in": "query",
            "name": "billing",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "standard",
                "byok"
              ],
              "default": "all"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Usage analytics + cost"
          },
          "400": {
            "description": "Invalid query parameters"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai/anthropic/v1/health": {
      "get": {
        "summary": "Health check for the messages proxy",
        "description": "Returns the org's effective routing target. Used by the sandbox\nbootstrap to verify the proxy is reachable and to surface which\nprovider family is being used (anthropic / google / kimi).\n",
        "tags": [
          "Projects",
          "AI"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status",
                    "model",
                    "provider"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    },
                    "model": {
                      "type": "string"
                    },
                    "provider": {
                      "type": "string",
                      "enum": [
                        "anthropic",
                        "google",
                        "kimi"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication error"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai/anthropic/v1/messages/count_tokens": {
      "post": {
        "summary": "Proxy Anthropic Count Tokens API",
        "description": "Proxies requests to the Anthropic Count Tokens API.\nUsed by Claude CLI for token counting before sending messages.\n",
        "tags": [
          "Projects",
          "AI"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Token count response from Anthropic"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai/anthropic/v1/messages": {
      "post": {
        "summary": "Proxy Anthropic Messages API",
        "description": "Accepts Anthropic-shape /v1/messages requests from Claude Code and\nroutes them to the org's default model. Bedrock-Anthropic for Claude\nvariants; Gemini via AI SDK for Gemini variants. The incoming `model`\nfield is logged but ignored — admin policy (org default) is law.\n\nStreaming and non-streaming both supported. Usage is tracked and\ncredits are deducted. Errors are returned in Anthropic shape:\n`{ type: \"error\", error: { type, message } }`.\n",
        "tags": [
          "Projects",
          "AI"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "messages",
                  "max_tokens"
                ],
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "Echoed back to the client; not used for routing"
                  },
                  "messages": {
                    "type": "array"
                  },
                  "max_tokens": {
                    "type": "integer"
                  },
                  "stream": {
                    "type": "boolean",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success — JSON (non-streaming) or SSE (streaming)"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Authentication error"
          },
          "403": {
            "description": "Permission / credits error"
          },
          "404": {
            "description": "Project not found"
          },
          "500": {
            "description": "Internal error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/ai/anthropic/v1/models": {
      "get": {
        "summary": "List Anthropic models",
        "description": "Proxies requests to the Anthropic Models API to list available models.\nThis is a read-only endpoint and does not consume credits.\nErrors are returned in Anthropic error format: { type: \"error\", error: { type, message } }\n",
        "tags": [
          "Projects",
          "AI"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "header",
            "name": "anthropic-version",
            "schema": {
              "type": "string",
              "default": "2023-06-01"
            },
            "description": "Anthropic API version"
          }
        ],
        "responses": {
          "200": {
            "description": "List of available Anthropic models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string"
                          },
                          "display_name": {
                            "type": "string"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "error"
                      ]
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "invalid_request_error"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "error"
                      ]
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "authentication_error"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Permission error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "error"
                      ]
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "permission_error"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "error"
                      ]
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "not_found_error"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "enum": [
                        "error"
                      ]
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "api_error"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/branches": {
      "get": {
        "summary": "List branches in the project's repository",
        "tags": [
          "Projects",
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Branch list"
          },
          "404": {
            "description": "Project or repository not found"
          }
        }
      },
      "post": {
        "summary": "Create a git branch in the project's repository",
        "description": "Creates a new branch in the project's linked GitHub repository.\nIf the project has no repository, provisions a BrainGrid-managed repo first.\n",
        "tags": [
          "Projects",
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Branch name (git ref rules apply)",
                    "example": "acossta/WKSP-1"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Branch created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "sha": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    },
                    "repository_created": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          },
          "409": {
            "description": "Branch already exists (treated as success with existing branch info)"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/builder/github-token": {
      "get": {
        "summary": "Mint a fresh repo-scoped GitHub token for the builder sandbox",
        "description": "Mints a short-lived GitHub installation token scoped to ONLY this project's repository (contents:write, metadata:read). The builder sandbox calls this to refresh its credential before the 60-minute GitHub installation-token TTL expires. The token is never cached and is scoped to a single repo, so its blast radius is minimal if intercepted.\n",
        "tags": [
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or short ID (PROJ-123)"
          }
        ],
        "responses": {
          "200": {
            "description": "A fresh repo-scoped GitHub token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string",
                      "description": "Repo-scoped GitHub installation token"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time",
                      "description": "ISO timestamp when the token expires (<= 60 min out)"
                    }
                  }
                },
                "example": {
                  "token": "ghs_xxxxxxxxxxxxxxxxxxxx",
                  "expiresAt": "2026-06-03T12:00:00Z"
                }
              }
            }
          },
          "404": {
            "description": "Project has no linked repository"
          }
        }
      }
    },
    "/v1/projects/{projectId}/clone": {
      "post": {
        "summary": "Clone a BrainGrid-managed project within the same org",
        "description": "Streams Server-Sent Events as the clone progresses through its\nphases. The final event is either `{type: \"complete\", data: {...}}`\nwith the new project's identifiers, or `{type: \"error\", data: {...}}`\nwith the failure reason.\n\nPhases emitted as `{type: \"phase\", data: {phase, status, ...}}`:\ncreating_project, copying_plan, creating_repository, mirroring_code,\ncopying_settings, provisioning_database (skipped for non-db), creating_workspace.\n",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stream of phase events ending in `complete` or `error`",
            "content": {
              "text/event-stream": {}
            }
          },
          "400": {
            "description": "Source ineligible"
          },
          "422": {
            "description": "Validation error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/config-values/{key}": {
      "get": {
        "summary": "Retrieve a single config value by key",
        "description": "Returns a single configuration value for the project's default environment,\nidentified by key. The value is returned decrypted.\n",
        "tags": [
          "Config Values"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Config key (alphanumeric, underscores, hyphens only)",
            "example": "MY_CONFIG_KEY"
          }
        ],
        "responses": {
          "200": {
            "description": "Config value retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "boolean"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "environment": {
                      "type": "string"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid project ID or key format"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Config key not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "patch": {
        "summary": "Update a config value by key",
        "description": "Updates a configuration value for the project's default environment.\nUses optimistic locking via updated_at to prevent concurrent overwrites.\n",
        "tags": [
          "Config Values"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Config key (alphanumeric, underscores, hyphens only)",
            "example": "MY_CONFIG_KEY"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "value",
                  "updated_at"
                ],
                "properties": {
                  "value": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "number"
                      },
                      {
                        "type": "boolean"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "New config value"
                  },
                  "updated_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Last known updated_at for optimistic locking"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Config value updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "boolean"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "environment": {
                      "type": "string"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Config key not found"
          },
          "409": {
            "description": "Optimistic lock conflict - value was modified since last read"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "summary": "Delete a config value by key",
        "description": "Deletes a configuration value from the project's default environment.\nUses optimistic locking via updated_at to prevent concurrent deletes.\n",
        "tags": [
          "Config Values"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Config key (alphanumeric, underscores, hyphens only)",
            "example": "MY_CONFIG_KEY"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "updated_at"
                ],
                "properties": {
                  "updated_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Last known updated_at for optimistic locking"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Config value deleted"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Config key not found"
          },
          "409": {
            "description": "Optimistic lock conflict - value was modified since last read"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/config-values": {
      "get": {
        "summary": "List all config values for a project",
        "description": "Returns all configuration values for the project's default environment.\nValues are returned decrypted.\n",
        "tags": [
          "Config Values"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Config values retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "additionalProperties": {
                        "oneOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "number"
                          },
                          {
                            "type": "boolean"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid project ID format"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "post": {
        "summary": "Create or set a config value",
        "description": "Sets a configuration value for the project. If the key already exists,\nit will be overwritten. The value is encrypted at rest.\n",
        "tags": [
          "Config Values"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key",
                  "value"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "description": "Config key (alphanumeric, underscores, hyphens only)",
                    "example": "MY_CONFIG_KEY"
                  },
                  "value": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "number"
                      },
                      {
                        "type": "boolean"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "Config value",
                    "example": "my-value"
                  },
                  "environment": {
                    "type": "string",
                    "description": "Environment name (defaults to \"default\")",
                    "example": "default"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Config value created/updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "boolean"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "environment": {
                      "type": "string"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/db/schemas": {
      "get": {
        "summary": "List user-visible schemas in the project's managed database",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schema names"
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "Project has no managed database"
          }
        }
      }
    },
    "/v1/projects/{projectId}/db/sql": {
      "post": {
        "summary": "Run arbitrary SQL against the project's managed database",
        "description": "Executes the supplied SQL against the project's `DIRECT_URL` via\npostgres-meta's pg pool. Returns row data + duration. Statement\ntimeout is 30s. Service-role-equivalent — any org member with\naccess to this project can run anything.\n",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "sql"
                ],
                "properties": {
                  "sql": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Query executed"
          },
          "400": {
            "description": "Invalid project or body"
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "Project has no managed database"
          },
          "422": {
            "description": "SQL parse / type validation failed"
          },
          "502": {
            "description": "Upstream database error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/db/tables/{name}/rows": {
      "get": {
        "summary": "Read rows from a table in a project's managed database",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "name",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "schema",
            "schema": {
              "type": "string",
              "default": "public"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 1000
            }
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "in": "query",
            "name": "order",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "filter",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Rows retrieved"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "Project has no managed database"
          },
          "422": {
            "description": "Database validation error"
          },
          "502": {
            "description": "Upstream database error"
          }
        }
      },
      "post": {
        "summary": "Insert a row into a table",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Row inserted"
          },
          "400": {
            "description": "Invalid input"
          },
          "409": {
            "description": "Constraint violation (unique",
            "FK)": null
          },
          "422": {
            "description": "Validation error (not-null",
            "check": null,
            "type)": null
          },
          "502": {
            "description": "Upstream database error"
          }
        }
      },
      "patch": {
        "summary": "Update rows matching filter(s) in a table",
        "description": "Requires at least one `filter` query parameter — a PATCH without\nfilters would mass-update the table and is rejected with 400.\n",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "filter",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rows updated"
          },
          "400": {
            "description": "Invalid input or missing filter"
          },
          "409": {
            "description": "Constraint violation"
          },
          "422": {
            "description": "Validation error"
          },
          "502": {
            "description": "Upstream database error"
          }
        }
      },
      "delete": {
        "summary": "Delete rows matching filter(s) in a table",
        "description": "Requires at least one `filter` query parameter — a DELETE without\nfilters would empty the table and is rejected with 400.\n",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "filter",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Rows deleted"
          },
          "400": {
            "description": "Invalid filter syntax or missing filter"
          },
          "409": {
            "description": "Constraint violation (e.g. FK in use)"
          },
          "502": {
            "description": "Upstream database error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/db/tables": {
      "get": {
        "summary": "List tables in a project's managed Postgres database",
        "description": "Returns schema-introspection metadata (columns, primary keys, foreign\nkeys) for all tables in the requested schemas. Backed by\n`@supabase/postgres-meta` against the project's `DIRECT_URL`.\n",
        "tags": [
          "BuilderData"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "query",
            "name": "schema",
            "required": false,
            "schema": {
              "type": "string",
              "default": "public"
            },
            "description": "Schema name. Defaults to `public`."
          }
        ],
        "responses": {
          "200": {
            "description": "Tables retrieved"
          },
          "400": {
            "description": "Invalid project ID"
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "Project has no managed database"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains/checkout": {
      "post": {
        "summary": "Create a Stripe Checkout session for a custom domain purchase",
        "description": "Re-verifies the domain's current price against live Vercel pricing,\ncreates a pending domain order, and returns a Stripe Checkout session\nURL. Only organization owners may purchase custom domains. The session\nmetadata embeds the order id and WHOIS contact for post-payment\nfulfillment.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "domainName",
                  "expectedPriceCents",
                  "pricingTier",
                  "whois"
                ],
                "properties": {
                  "domainName": {
                    "type": "string",
                    "description": "Apex domain to purchase (e.g., my-cool-app.com)"
                  },
                  "expectedPriceCents": {
                    "type": "integer",
                    "description": "Retail price in cents the client expects for the tier"
                  },
                  "pricingTier": {
                    "type": "string",
                    "enum": [
                      "TIER_1",
                      "TIER_2",
                      "TIER_3",
                      "TIER_4",
                      "TIER_5"
                    ]
                  },
                  "whois": {
                    "type": "object",
                    "description": "WHOIS registrant contact required by the registrar"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Checkout session created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "orderId": {
                      "type": "string"
                    },
                    "checkoutUrl": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed or domain price changed (PRICE_MISMATCH)"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Only organization owners can purchase custom domains (FORBIDDEN)"
          },
          "404": {
            "description": "Project not found"
          },
          "500": {
            "description": "Stripe checkout session creation failed (DOMAIN_CHECKOUT_FAILED)"
          },
          "503": {
            "description": "Vercel API unreachable (VERCEL_API_UNREACHABLE)"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains/orders/{orderId}/retry-config": {
      "post": {
        "summary": "Retry domain configuration",
        "description": "Manually retries the DNS configuration step for a purchased domain\nwhose configuration previously failed. Allows up to 5 retries; after\nthat the user must contact support (an admin alert is raised).\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "orderId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Domain order ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Configuration retry initiated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "order": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "overall_state": {
                          "type": "string"
                        },
                        "vercel_order_status": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Retry limit exceeded (RETRY_LIMIT_EXCEEDED) or invalid order ID"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or domain order not found"
          },
          "409": {
            "description": "Order is not in a retryable state (DOMAIN_ORDER_INVALID_STATE)"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains/orders/{orderId}": {
      "get": {
        "summary": "Get a domain order's current status",
        "description": "Returns the current lifecycle state of a managed domain order so the UI\ncan render and poll the order-status tracker. Sensitive metadata (WHOIS\ncontact, payment-intent id) is never returned.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "orderId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Domain order ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Current domain order state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "project_id": {
                      "type": "string"
                    },
                    "organization_id": {
                      "type": "string"
                    },
                    "user_id": {
                      "type": "string"
                    },
                    "domain_name": {
                      "type": "string"
                    },
                    "price_paid_cents": {
                      "type": "integer"
                    },
                    "pricing_tier": {
                      "type": "string"
                    },
                    "stripe_session_id": {
                      "type": "string",
                      "nullable": true
                    },
                    "overall_state": {
                      "type": "string"
                    },
                    "payment_status": {
                      "type": "string"
                    },
                    "vercel_order_status": {
                      "type": "string"
                    },
                    "refund_status": {
                      "type": "string"
                    },
                    "error_message": {
                      "type": "string",
                      "nullable": true
                    },
                    "retry_count": {
                      "type": "integer"
                    },
                    "max_config_retries": {
                      "type": "integer"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid order ID"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or domain order not found (DOMAIN_ORDER_NOT_FOUND)"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains/orders": {
      "get": {
        "summary": "List domain orders, or resolve one by Stripe session",
        "description": "Without query params, returns the project's domain orders newest-first\nso the UI can surface an in-progress order. With `session_id`, resolves\nthe single order behind a Stripe Checkout session — used when the\nbrowser returns from Checkout carrying only the session id. Sensitive\nmetadata (WHOIS contact, payment-intent id) is never returned.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "query",
            "name": "session_id",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Stripe Checkout session id to resolve a single order"
          }
        ],
        "responses": {
          "200": {
            "description": "A list of orders, or a single resolved order",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "orders": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        }
                      }
                    },
                    {
                      "type": "object",
                      "description": "Single order (when session_id is supplied)"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found, or no order for the given session_id"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains": {
      "get": {
        "summary": "Get custom domain status",
        "description": "Returns the current custom domain configuration for the project,\nincluding verification status and required DNS records.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Domain status (null if no custom domain configured)"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "post": {
        "summary": "Add a custom domain",
        "description": "Adds a custom domain to the project's Vercel deployment.\nReturns the domain state including DNS verification records\nthat the customer must add at their registrar.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "domain"
                ],
                "properties": {
                  "domain": {
                    "type": "string",
                    "description": "The custom domain to add (e.g., app.example.com)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Domain added with DNS verification records"
          },
          "400": {
            "description": "Invalid domain format"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found or no Vercel hosting provisioned"
          },
          "409": {
            "description": "Domain is already in use by another project"
          }
        }
      },
      "delete": {
        "summary": "Remove custom domain",
        "description": "Removes the custom domain from the project's Vercel deployment.\nThe auto-assigned bgridapp.com domain remains active.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "204": {
            "description": "Domain removed"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found or no custom domain configured"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains/search": {
      "get": {
        "summary": "Search domain availability and retail price",
        "description": "Checks whether a domain is available for purchase through BrainGrid's\nmanaged registrar and maps its wholesale cost to a retail pricing\ntier. Available domains whose wholesale cost exceeds the supported\nrange come back unavailable with reason PREMIUM_EXCEEDS_LIMIT.\n\nTwo modes: pass `name` (a bare root label like `my-cool-app`) for a\nbulk search across the managed TLDs (.build, .com, .net, .org, .co,\n.io), returning a `results` array; or pass `domain` (a fully qualified apex\ndomain) for a single-domain lookup returning one result object.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "query",
            "name": "name",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Bare root label to search across managed TLDs (e.g., my-cool-app)"
          },
          {
            "in": "query",
            "name": "domain",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Fully qualified apex domain for a single lookup (e.g., my-cool-app.com)"
          }
        ],
        "responses": {
          "200": {
            "description": "Search result(s) with availability, tier, and retail price",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "description": "Single-domain result (when `domain` is supplied)",
                      "properties": {
                        "domain": {
                          "type": "string"
                        },
                        "available": {
                          "type": "boolean"
                        },
                        "tier": {
                          "type": "string",
                          "nullable": true,
                          "enum": [
                            "TIER_1",
                            "TIER_2",
                            "TIER_3",
                            "TIER_4",
                            "TIER_5"
                          ]
                        },
                        "retailPrice": {
                          "type": "number",
                          "nullable": true
                        },
                        "currency": {
                          "type": "string",
                          "enum": [
                            "USD"
                          ]
                        },
                        "reason": {
                          "type": "string",
                          "enum": [
                            "PREMIUM_EXCEEDS_LIMIT"
                          ]
                        }
                      }
                    },
                    {
                      "type": "object",
                      "description": "Bulk results (when `name` is supplied)",
                      "properties": {
                        "results": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "domain": {
                                "type": "string"
                              },
                              "available": {
                                "type": "boolean"
                              },
                              "tier": {
                                "type": "string",
                                "nullable": true
                              },
                              "retailPrice": {
                                "type": "number",
                                "nullable": true
                              },
                              "currency": {
                                "type": "string",
                                "enum": [
                                  "USD"
                                ]
                              },
                              "reason": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid domain format (INVALID_DOMAIN_FORMAT)"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          },
          "429": {
            "description": "Vercel API rate limit exceeded"
          },
          "503": {
            "description": "Vercel API unreachable (VERCEL_API_UNREACHABLE)"
          }
        }
      }
    },
    "/v1/projects/{projectId}/domains/verify": {
      "post": {
        "summary": "Verify custom domain DNS",
        "description": "Triggers a DNS verification check for the project's pending custom domain.\nThe customer must have added the required DNS records at their registrar\nbefore calling this endpoint.\n",
        "tags": [
          "Projects",
          "Domains"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Verification result with updated domain state"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found or no custom domain configured"
          }
        }
      }
    },
    "/v1/projects/{projectId}/environment-variables/{key}": {
      "get": {
        "summary": "Retrieve a single environment variable by key",
        "description": "Returns a single environment variable for the project's default environment,\nidentified by key. The value is returned decrypted.\n",
        "tags": [
          "Environment Variables"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Environment variable key (alphanumeric, underscores, hyphens only)",
            "example": "DATABASE_URL"
          }
        ],
        "responses": {
          "200": {
            "description": "Environment variable retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "ENVIRONMENT_VARIABLE"
                      ]
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid project ID or key format"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Environment variable not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "patch": {
        "summary": "Update an environment variable by key",
        "description": "Updates an environment variable value for the project's default environment.\nThe value is encrypted at rest.\n",
        "tags": [
          "Environment Variables"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Environment variable key (alphanumeric, underscores, hyphens only)",
            "example": "DATABASE_URL"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "value",
                  "updated_at"
                ],
                "properties": {
                  "value": {
                    "type": "string",
                    "description": "New environment variable value"
                  },
                  "updated_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Last known updated_at for optimistic locking"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Environment variable updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "ENVIRONMENT_VARIABLE"
                      ]
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Environment variable not found"
          },
          "409": {
            "description": "Optimistic lock conflict - value was modified since last read"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "summary": "Delete an environment variable by key",
        "description": "Deletes an environment variable from the project's default environment.\nUses optimistic locking via updated_at to prevent concurrent deletes.\n",
        "tags": [
          "Environment Variables"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "key",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Environment variable key (alphanumeric, underscores, hyphens only)",
            "example": "DATABASE_URL"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "updated_at"
                ],
                "properties": {
                  "updated_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Last known updated_at for optimistic locking"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Environment variable deleted"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Environment variable not found"
          },
          "409": {
            "description": "Optimistic lock conflict - value was modified since last read"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/environment-variables/effective": {
      "get": {
        "summary": "List the effective env vars for a project (user + platform-managed)",
        "description": "Returns the merged set of env vars surfaced in project settings: user\n`ENVIRONMENT_VARIABLE` rows plus platform-managed `CONFIG_VALUE` rows\n(Supabase credentials, `DATABASE_URL`, etc.) mapped to their Next.js\nenv var names. User values win on key collision. `VERCEL_*` keys are\nexcluded. Each variable carries `isSensitive` and `source` flags.\n",
        "tags": [
          "Environment Variables"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Effective env vars retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "variables": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "value": {
                            "type": "string"
                          },
                          "isSensitive": {
                            "type": "boolean"
                          },
                          "source": {
                            "type": "string",
                            "enum": [
                              "user",
                              "platform"
                            ]
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "reservedKeys": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Env var names that are platform-managed and cannot be overridden."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid project ID format"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/environment-variables": {
      "get": {
        "summary": "List all environment variables for a project",
        "description": "Returns all environment variables for the project's default environment.\nValues are returned decrypted.\n",
        "tags": [
          "Environment Variables"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Environment variables retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "value": {
                            "type": "string"
                          },
                          "type": {
                            "type": "string",
                            "enum": [
                              "ENVIRONMENT_VARIABLE"
                            ]
                          },
                          "createdAt": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid project ID format"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "post": {
        "summary": "Create an environment variable",
        "description": "Creates a new environment variable for the project. Returns 409 if the\nkey already exists. The value is encrypted at rest.\n",
        "tags": [
          "Environment Variables"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key",
                  "value"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "description": "Environment variable key (alphanumeric, underscores, hyphens only)",
                    "example": "DATABASE_URL"
                  },
                  "value": {
                    "type": "string",
                    "description": "Environment variable value",
                    "example": "postgres://localhost:5432/mydb"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Environment variable created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    },
                    "type": {
                      "type": "string",
                      "enum": [
                        "ENVIRONMENT_VARIABLE"
                      ]
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updatedAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "409": {
            "description": "Environment variable key already exists, or key is reserved for platform-managed values (errorCode `PLATFORM_RESERVED_KEY`)"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/epics/{epicId}/execution-graph": {
      "get": {
        "summary": "Get execution graph for an Epic",
        "description": "Returns the dependency graph and suggested execution order for all requirements\nbelonging to the specified Epic. Requirements are topologically sorted based on\ntheir blocked_by_artifact_ids dependencies.\n",
        "tags": [
          "Projects",
          "Epics"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "epicId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Epic ID (UUID or EPIC-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Execution graph retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "epic_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "epic_name": {
                      "type": "string"
                    },
                    "requirements": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "short_id": {
                            "type": "string",
                            "description": "Human-readable ID (e.g., \"REQ-123\")"
                          },
                          "name": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "PLANNED",
                              "IN_PROGRESS",
                              "COMPLETED",
                              "CANCELLED",
                              "REVIEW",
                              "IDEA"
                            ]
                          },
                          "execution_order": {
                            "type": "integer",
                            "description": "Suggested execution order (1-based)"
                          },
                          "is_ready": {
                            "type": "boolean",
                            "description": "True if all blocking dependencies are completed"
                          },
                          "blocked_by": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Array of short_ids that this requirement is blocked by"
                          },
                          "blocks": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            },
                            "description": "Array of short_ids that this requirement blocks"
                          }
                        }
                      }
                    },
                    "metadata": {
                      "type": "object",
                      "properties": {
                        "total_requirements": {
                          "type": "integer"
                        },
                        "ready_to_start": {
                          "type": "integer",
                          "description": "Count of PLANNED requirements with no incomplete dependencies"
                        },
                        "in_progress": {
                          "type": "integer"
                        },
                        "completed": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Epic not found or not in this project"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/epics/{epicId}/requirements": {
      "get": {
        "summary": "List child requirements of an epic",
        "description": "Lists all child requirements of an epic with task progress and pagination",
        "tags": [
          "Projects",
          "Epics",
          "Requirements"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "epicId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Requirements retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Epic not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/epics/{epicId}": {
      "get": {
        "summary": "Get epic details",
        "description": "Retrieves detailed information about a specific epic",
        "tags": [
          "Projects",
          "Epics"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "epicId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Epic details retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Epic not found"
          }
        }
      },
      "patch": {
        "summary": "Update epic",
        "description": "Updates epic properties",
        "tags": [
          "Projects",
          "Epics"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "epicId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "PLANNED",
                      "IN_PROGRESS",
                      "COMPLETED",
                      "CANCELLED",
                      "REVIEW",
                      "IDEA"
                    ]
                  },
                  "content": {
                    "type": "string",
                    "nullable": true
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "assigned_to": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  },
                  "parent_artifact_id": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  },
                  "blocked_by_artifact_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Epic updated successfully"
          },
          "400": {
            "description": "Validation error"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Epic not found"
          },
          "422": {
            "description": "Unprocessable entity (dependency errors)"
          }
        }
      },
      "delete": {
        "summary": "Delete epic",
        "description": "Deletes an epic and optionally its child requirements",
        "tags": [
          "Projects",
          "Epics"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "epicId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "cascade",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Whether to delete child requirements"
          }
        ],
        "responses": {
          "200": {
            "description": "Epic deleted successfully"
          },
          "400": {
            "description": "Epic has child requirements (use cascade=true)"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Epic not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/epics": {
      "get": {
        "summary": "List epics for a project",
        "description": "Lists epics for a specific project with pagination and tag filtering",
        "tags": [
          "Projects",
          "Epics"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "in": "query",
            "name": "tags",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated tag names (AND logic)",
            "example": "auth,security"
          },
          {
            "in": "query",
            "name": "include",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list of optional fields to include (e.g. \"task_progress\"). Defaults to all fields included.",
            "example": "task_progress"
          }
        ],
        "responses": {
          "200": {
            "description": "Epics retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "post": {
        "summary": "Create epic in project",
        "description": "Creates a new epic within a specific project",
        "tags": [
          "Projects",
          "Epics"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "content": {
                    "type": "string",
                    "nullable": true
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "assigned_to": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  },
                  "parent_artifact_id": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  },
                  "complexity": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "readiness": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Epic created successfully"
          },
          "400": {
            "description": "Validation error"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/github-repo/available-accounts": {
      "get": {
        "summary": "List GitHub accounts available for repository creation",
        "description": "Returns all GitHub accounts the user can create repositories in,\naggregated from OAuth, GitHub App installations, and the BrainGrid\nmanaged fallback. The BrainGrid entry is always present as the last item.\n",
        "tags": [
          "Projects",
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Available accounts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accounts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "type": "string",
                            "enum": [
                              "oauth",
                              "installation",
                              "braingrid"
                            ]
                          },
                          "login": {
                            "type": "string"
                          },
                          "avatarUrl": {
                            "type": "string",
                            "nullable": true
                          },
                          "installationId": {
                            "type": "number"
                          },
                          "hasWriteAccess": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "403": {
            "description": "User is not a member of the project"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/github-repo": {
      "post": {
        "summary": "Provision a GitHub repository for a project",
        "description": "Creates a new GitHub repository and links it to the specified project.\nUses 3-tier auth: User OAuth > GitHub App installation > BrainGrid installation token.\nOptionally creates from a template repository.\n",
        "tags": [
          "Projects",
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Repository name (alphanumeric, hyphens, underscores, periods)",
                    "example": "my-new-repo"
                  },
                  "description": {
                    "type": "string",
                    "description": "Short repository description (max 350 chars)"
                  },
                  "use_braingrid_account": {
                    "type": "boolean",
                    "description": "Create the repo in BrainGrid's GitHub org instead of the user's"
                  },
                  "template": {
                    "type": "string",
                    "description": "Template key from the config map (defaults to \"base\")",
                    "example": "base"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Repository created and linked to project",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "number"
                    },
                    "name": {
                      "type": "string"
                    },
                    "full_name": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string",
                      "nullable": true
                    },
                    "private": {
                      "type": "boolean"
                    },
                    "html_url": {
                      "type": "string"
                    },
                    "clone_url": {
                      "type": "string"
                    },
                    "ssh_url": {
                      "type": "string"
                    },
                    "default_branch": {
                      "type": "string"
                    },
                    "created_at": {
                      "type": "string"
                    },
                    "auth_type": {
                      "type": "string",
                      "enum": [
                        "user_oauth",
                        "installation",
                        "braingrid_managed"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          },
          "409": {
            "description": "Repository name already exists or project already has a repo"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/hosting/deployments/{deploymentId}/events": {
      "get": {
        "summary": "Get build events (stdout/stderr) for a deployment",
        "description": "Returns the build log stream as discrete events, used to render full build logs on the deployment detail page (especially for failed builds).",
        "tags": [
          "Hosting"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "deploymentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 5000,
              "default": 500
            }
          },
          {
            "in": "query",
            "name": "since",
            "schema": {
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "until",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of deployment build events"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or deployment not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/hosting/deployments/{deploymentId}": {
      "get": {
        "summary": "Get a single deployment's detail",
        "tags": [
          "Hosting"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "deploymentId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deployment detail with timings",
            "commit": null,
            "and error info": null
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or deployment not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/hosting/deployments": {
      "get": {
        "summary": "List production deployments for a project",
        "tags": [
          "Hosting"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "in": "query",
            "name": "since",
            "schema": {
              "type": "integer"
            },
            "description": "Unix ms — list deployments created at/after this time"
          },
          {
            "in": "query",
            "name": "until",
            "schema": {
              "type": "integer"
            },
            "description": "Unix ms — list deployments created at/before this time"
          },
          {
            "in": "query",
            "name": "state",
            "schema": {
              "type": "string",
              "enum": [
                "READY",
                "ERROR",
                "BUILDING",
                "QUEUED",
                "CANCELED"
              ]
            }
          },
          {
            "in": "query",
            "name": "branch",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of production deployments"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Hosting not provisioned"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/hosting/logs": {
      "get": {
        "summary": "Get runtime logs for a specific deployment",
        "description": "Runtime request logs scoped to a single deployment.\nSupports a search minilanguage in the `q` parameter:\n  - `status:5xx` or `status:500,502`\n  - `path:/api/*`\n  - `region:iad1`\n  - `requestId:abc`\n  - `level:error,warning`\nUnknown tokens and trailing free text are matched against `path` + `message`.\n",
        "tags": [
          "Hosting"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "deployment_id",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "since",
            "schema": {
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "until",
            "schema": {
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 100
            }
          },
          {
            "in": "query",
            "name": "q",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list — accepts `500`, `5xx`, `4xx`, etc."
          },
          {
            "in": "query",
            "name": "level",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list of `error`, `warning`, `info`."
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated runtime logs"
          },
          "400": {
            "description": "Missing or invalid deployment_id"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or hosting not provisioned"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/hosting/redeploy": {
      "post": {
        "summary": "Trigger a fresh production deployment of the latest commit",
        "description": "Rebuilds and redeploys the project's most recent production commit.\nReturns immediately with the new deployment id; poll\n`/hosting/deployments/{deploymentId}` for build status.\n",
        "tags": [
          "Hosting"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Redeploy triggered"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or hosting not provisioned"
          },
          "409": {
            "description": "No prior deployment to redeploy"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/hosting": {
      "get": {
        "summary": "Get hosting overview for a project",
        "tags": [
          "Hosting"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or PROJ-XXX"
          }
        ],
        "responses": {
          "200": {
            "description": "Hosting status, live URL, aliases, and current production deployment"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found or hosting not provisioned"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "500": {
            "description": "Hosting integration not configured"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/knowledge/memory/{slug}": {
      "get": {
        "summary": "Read a single agent memory entry",
        "description": "Fetches and parses `.braingrid/memory/{slug}.md` from the project's\nlinked repository. Without `ref`, scans the rollup branch set (active\nworkspace branches first, then `repo.defaultBranch`) and returns the\nfirst hit; the response's `branch`/`unmerged` fields record where the\nreturned version lives. With `ref`, reads only that branch (mirrors\nthe `entry` mode of the `recall_memory` agent tool).\n\nAgent instruction files (`CLAUDE.md`/`AGENTS.md`) are also addressable:\npass the file's full repo path as the slug (URL-encoded). Because this\nis a single path segment, only root-level agent files (`CLAUDE.md`)\nresolve here; nested files (`src/AGENTS.md`) are surfaced via the list\nendpoint and the `recall_memory` tool instead.\n",
        "tags": [
          "Projects",
          "Knowledge"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "PROJ-N short ID or project UUID"
          },
          {
            "in": "path",
            "name": "slug",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Memory entry slug (filename without `.md`)"
          },
          {
            "in": "query",
            "name": "ref",
            "schema": {
              "type": "string"
            },
            "description": "Optional branch to scope the read to. Without this the rollup branch set is used."
          }
        ],
        "responses": {
          "200": {
            "description": "Memory entry",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "memory": {
                      "type": "object",
                      "properties": {
                        "branch": {
                          "type": "string",
                          "description": "Branch the returned entry was read from."
                        },
                        "unmerged": {
                          "type": "boolean",
                          "description": "True when branch differs from the repo default."
                        },
                        "entry": {
                          "type": "object",
                          "properties": {
                            "slug": {
                              "type": "string"
                            },
                            "path": {
                              "type": "string"
                            },
                            "type": {
                              "type": "string",
                              "enum": [
                                "user",
                                "feedback",
                                "project",
                                "reference",
                                "agent"
                              ]
                            },
                            "name": {
                              "type": "string"
                            },
                            "description": {
                              "type": "string"
                            },
                            "body": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Memory entry not found",
            "or repository not linked to project": null
          },
          "413": {
            "description": "Memory entry exists but is too large to read inline"
          },
          "422": {
            "description": "File exists but is not a recognizable memory entry"
          }
        }
      }
    },
    "/v1/projects/{projectId}/knowledge/memory": {
      "get": {
        "summary": "List agent memory entries for a project",
        "description": "Returns parsed `.braingrid/memory/` entries. Without `ref`, returns a\nrollup across `repo.defaultBranch` + up to 5 recent active-workspace\nbranches; each slug is deduped to the latest-`updatedAt` version with\n`entry.branch` recording the winning branch. With `ref`, scans only\nthat branch (backward-compat). The repo's own `CLAUDE.md`/`AGENTS.md`\nfiles (recursive) are also surfaced as read-only `agent`-type entries\nwhose `slug` is the file's repo path; `no-folder` is returned only when\n`.braingrid/memory/` is absent AND there are no agent files.\n",
        "tags": [
          "Projects",
          "Knowledge"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "PROJ-N short ID or project UUID"
          },
          {
            "in": "query",
            "name": "ref",
            "schema": {
              "type": "string"
            },
            "description": "Optional single branch to scope the read to. Without this the rollup branch set is used."
          }
        ],
        "responses": {
          "200": {
            "description": "Memory list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "memory": {
                      "type": "object",
                      "properties": {
                        "status": {
                          "type": "string",
                          "enum": [
                            "no-folder",
                            "empty",
                            "ready"
                          ]
                        },
                        "scannedBranches": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "description": "Branches the rollup considered (default + recent active workspaces, or `[ref]` when scoped)."
                        },
                        "defaultBranch": {
                          "type": "string"
                        },
                        "entries": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "slug": {
                                "type": "string"
                              },
                              "type": {
                                "type": "string",
                                "enum": [
                                  "user",
                                  "feedback",
                                  "project",
                                  "reference",
                                  "agent"
                                ]
                              },
                              "name": {
                                "type": "string"
                              },
                              "description": {
                                "type": "string"
                              },
                              "body": {
                                "type": "string"
                              },
                              "path": {
                                "type": "string"
                              },
                              "updatedAt": {
                                "type": "string",
                                "format": "date-time",
                                "nullable": true
                              },
                              "branch": {
                                "type": "string",
                                "description": "Branch the winning version of this entry came from."
                              },
                              "unmerged": {
                                "type": "boolean",
                                "description": "True when branch differs from defaultBranch."
                              }
                            }
                          }
                        },
                        "githubBlobUrlBase": {
                          "type": "string",
                          "description": "Blob base without a branch segment; build per-entry URLs as `{base}/{entry.branch}/{entry.path}`."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project has no linked repository"
          }
        }
      }
    },
    "/v1/projects/{projectId}/knowledge/memory/search": {
      "get": {
        "summary": "Search agent memory entries",
        "description": "Substring search across `name`, `description`, and `body` of memory\nentries. Without `ref`, searches the rollup branch set (default + up\nto 5 active workspace branches); per slug the highest-scoring entry\non the most-recently-active branch wins. With `ref`, searches only\nthat branch. Mirrors the `search` mode of the `recall_memory` agent\ntool.\n",
        "tags": [
          "Projects",
          "Knowledge"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "PROJ-N short ID or project UUID"
          },
          {
            "in": "query",
            "name": "q",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Search query"
          },
          {
            "in": "query",
            "name": "ref",
            "schema": {
              "type": "string"
            },
            "description": "Optional single branch to scope the search to. Without this the rollup branch set is used."
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 5
            },
            "description": "Maximum results to return (capped at 50)."
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "memory": {
                      "type": "object",
                      "properties": {
                        "branch": {
                          "type": "string",
                          "description": "Single-branch mode the searched ref; rollup mode the default branch."
                        },
                        "scannedBranches": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "defaultBranch": {
                          "type": "string"
                        },
                        "entries": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "slug": {
                                "type": "string"
                              },
                              "path": {
                                "type": "string"
                              },
                              "type": {
                                "type": "string",
                                "enum": [
                                  "user",
                                  "feedback",
                                  "project",
                                  "reference"
                                ]
                              },
                              "name": {
                                "type": "string"
                              },
                              "description": {
                                "type": "string"
                              },
                              "body": {
                                "type": "string"
                              },
                              "branch": {
                                "type": "string"
                              },
                              "unmerged": {
                                "type": "boolean"
                              }
                            }
                          }
                        },
                        "truncated": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing `q` query parameter"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project has no linked repository"
          }
        }
      }
    },
    "/v1/projects/{projectId}/provision/authentication": {
      "post": {
        "summary": "Configure authentication mode for a project",
        "description": "Sets the authentication strategy for a project. Requires a managed\ndatabase to already be provisioned. OWNER-only.\n",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or short ID (PROJ-XXX)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "auth_mode"
                ],
                "additionalProperties": false,
                "properties": {
                  "auth_mode": {
                    "type": "string",
                    "enum": [
                      "PUBLIC",
                      "GOOGLE",
                      "MAGIC_LINK"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Auth mode updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "auth_mode"
                  ],
                  "properties": {
                    "auth_mode": {
                      "type": "string",
                      "enum": [
                        "PUBLIC",
                        "GOOGLE",
                        "MAGIC_LINK"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "OWNER role required"
          },
          "404": {
            "description": "Project not found"
          },
          "409": {
            "description": "Database not provisioned"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/provision/database": {
      "post": {
        "summary": "Provision a managed database for a project",
        "description": "Provisions a managed database for the project and (best-effort) injects\ncredentials into the active BrainGrid-managed sandbox. OWNER-only.\n\nReturns a vendor-neutral response — no implementation-specific URLs or\nkeys are exposed.\n",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or short ID (PROJ-XXX)"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Database provisioned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "manage_database",
                    "database_ref"
                  ],
                  "properties": {
                    "manage_database": {
                      "type": "boolean",
                      "const": true
                    },
                    "database_ref": {
                      "type": "string",
                      "description": "Opaque reference for the provisioned database"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "OWNER role required"
          },
          "404": {
            "description": "Project not found"
          },
          "409": {
            "description": "Database already provisioned for this project"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/archive": {
      "get": {
        "summary": "Download a ZIP snapshot of the repo at a ref",
        "description": "Returns a 302 redirect to a signed download URL valid for a short\nwindow. Requires a paid plan — trial orgs get 402.\n",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "ref",
            "schema": {
              "type": "string",
              "default": "HEAD"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to signed archive URL"
          },
          "400": {
            "description": "Invalid query"
          },
          "402": {
            "description": "Paid plan required"
          },
          "404": {
            "description": "Ref not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/blob": {
      "get": {
        "summary": "Get a file blob at a path on a ref",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "ref",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Blob (may be truncated for large files)"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Path or ref not found"
          },
          "413": {
            "description": "Blob too large to return inline"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/branches": {
      "get": {
        "summary": "List branches in the managed repository",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Branch list"
          },
          "400": {
            "description": "Repository is not BrainGrid-managed"
          },
          "404": {
            "description": "Project or repository not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/commits/{sha}": {
      "get": {
        "summary": "Get a single commit with file diffs",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "sha",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Commit detail with files and patches"
          },
          "400": {
            "description": "Invalid SHA"
          },
          "404": {
            "description": "Commit not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/commits": {
      "get": {
        "summary": "List commits on a ref",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "ref",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated commit list"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Ref not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      },
      "post": {
        "summary": "Commit one or more files to a branch",
        "description": "Atomically commits files to a branch of the project's BrainGrid-managed\nrepository. Creates the branch from the default branch when it doesn't\nexist (unless `create_branch_if_missing` is false).\n",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "branch",
                  "message",
                  "files"
                ],
                "properties": {
                  "branch": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  },
                  "create_branch_if_missing": {
                    "type": "boolean",
                    "default": true
                  },
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "path",
                        "content"
                      ],
                      "properties": {
                        "path": {
                          "type": "string"
                        },
                        "content": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Commit created — returns commitSha + branch"
          },
          "400": {
            "description": "Invalid body or repository not managed"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or repository not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/files": {
      "get": {
        "summary": "List every file path at a ref (recursive)",
        "description": "Returns a flat list of all blob paths at the given ref. Used to power\nfile-jump / command-palette experiences. May be truncated for very large\nrepos (GitHub caps tree responses).\n",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "ref",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Flat file list (may be truncated)"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Ref not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/pulls/{number}/commits": {
      "get": {
        "summary": "List commits on a pull request",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "number",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Commit list"
          },
          "400": {
            "description": "Invalid number"
          },
          "404": {
            "description": "Pull request not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/pulls/{number}/files": {
      "get": {
        "summary": "List files changed in a pull request (with patches)",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "number",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File diff list"
          },
          "400": {
            "description": "Invalid number"
          },
          "404": {
            "description": "Pull request not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/pulls/{number}": {
      "get": {
        "summary": "Get pull request detail",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "number",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pull request detail"
          },
          "400": {
            "description": "Invalid number"
          },
          "404": {
            "description": "Pull request not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/pulls": {
      "get": {
        "summary": "List pull requests",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "state",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "closed",
                "merged",
                "all"
              ],
              "default": "open"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated pull request list"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Project or repository not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      },
      "post": {
        "summary": "Open a pull request",
        "description": "Opens a PR on the project's BrainGrid-managed repository. `base` defaults\nto the repo's default branch. Idempotent — an existing open PR for the\nsame head/base is returned instead of erroring.\n",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "head",
                  "title"
                ],
                "properties": {
                  "head": {
                    "type": "string"
                  },
                  "base": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "body": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pull request opened — returns number + url"
          },
          "400": {
            "description": "Invalid body or repository not managed"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or repository not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/readme": {
      "get": {
        "summary": "Get the README for the repository (or for a specific ref)",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "ref",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "README markdown (or null if missing)"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Project or repository not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository": {
      "get": {
        "summary": "Get the BrainGrid-managed repository for a project",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or PROJ-XXX"
          }
        ],
        "responses": {
          "200": {
            "description": "Repository metadata"
          },
          "400": {
            "description": "Repository is not BrainGrid-managed"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or repository not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/repository/tree": {
      "get": {
        "summary": "List entries at a path on a ref",
        "tags": [
          "Repository"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "ref",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "path",
            "schema": {
              "type": "string",
              "default": ""
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tree entries"
          },
          "400": {
            "description": "Invalid query"
          },
          "404": {
            "description": "Path or ref not found"
          },
          "429": {
            "description": "Upstream rate limit"
          },
          "502": {
            "description": "Upstream provider error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}/create-git-branch": {
      "post": {
        "summary": "Create GitHub branch for requirement",
        "description": "Creates a new GitHub branch for a requirement in its associated repository.\nThe requirement must be associated with a GitHub repository. The branch name\nmust follow Git naming conventions (no spaces, no special characters like ~^:?*[\\,\nno leading/trailing slashes or dots, no consecutive dots). After successful\nbranch creation, the requirement's branch field is updated with the new branch name\nand a requirement.branch_created event is published.\n",
        "tags": [
          "Requirements",
          "GitHub"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)",
            "example": "PROJ-42"
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Requirement ID (UUID or REQ-XXX format)",
            "example": "REQ-123"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "branchName"
                ],
                "properties": {
                  "branchName": {
                    "type": "string",
                    "description": "Name for the new branch (must follow Git naming conventions)",
                    "example": "feature/user-authentication",
                    "pattern": "^(?![\\.\\-/])(?!.*\\.\\.)(?!.*[~^:?*\\[\\\\])[^\\s]+(?<![\\.\\-/])$"
                  },
                  "baseBranch": {
                    "type": "string",
                    "description": "Base branch to create from (falls back to project config base_branch, then repository default branch)",
                    "example": "main"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Branch created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "branch": {
                      "type": "object",
                      "description": "Details of the created branch",
                      "properties": {
                        "name": {
                          "type": "string",
                          "example": "feature/user-authentication"
                        },
                        "sha": {
                          "type": "string",
                          "example": "abc123def456..."
                        },
                        "url": {
                          "type": "string",
                          "example": "https://api.github.com/repos/owner/repo/git/refs/heads/feature/user-authentication"
                        }
                      }
                    },
                    "requirement": {
                      "type": "object",
                      "description": "Updated requirement information",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid",
                          "example": "550e8400-e29b-41d4-a716-446655440000"
                        },
                        "branch": {
                          "type": "string",
                          "example": "feature/user-authentication"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON or validation error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errorId": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "403": {
            "description": "Insufficient permissions or organization suspended",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "INSUFFICIENT_PERMISSIONS",
                        "ORG_SUSPENDED"
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Project or requirement not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "PROJECT_NOT_FOUND",
                        "REQUIREMENT_NOT_FOUND"
                      ]
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "Branch already exists",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errorId": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Requirement not associated with repository or validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "field": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errorId": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}/review/acceptance": {
      "post": {
        "summary": "Perform AI code review for a requirement",
        "description": "Performs AI-powered code review on a pull request for a specific requirement.\nValidates that the PR satisfies the requirement's acceptance criteria.\nStreams the review response back to the client in real-time.\n",
        "tags": [
          "Review"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or short ID (PROJ-123)"
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Requirement UUID or short ID (REQ-123)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "pullRequest"
                ],
                "properties": {
                  "pullRequest": {
                    "type": "string",
                    "description": "Pull request number (e.g., \"123\") or full GitHub URL",
                    "example": "123"
                  }
                }
              },
              "examples": {
                "withNumber": {
                  "summary": "Using PR number",
                  "value": {
                    "pullRequest": "123"
                  }
                },
                "withUrl": {
                  "summary": "Using full URL",
                  "value": {
                    "pullRequest": "https://github.com/owner/repo/pull/123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Streaming review response",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "description": "Real-time streaming response containing the AI-generated code review.\nThe review includes analysis of code changes, acceptance criteria validation,\nand recommendations for improvements.\n"
                },
                "example": "# Code Review for PR #123\n\n## Summary\nThis pull request implements user authentication using OAuth 2.0...\n\n## Acceptance Criteria Review\n✅ OAuth provider configuration implemented\n✅ Callback handler created with token exchange\n⚠️ Session management partially complete\n\n## Code Quality\n- Good separation of concerns\n- Missing error handling in callback endpoint\n- Consider adding rate limiting\n\n## Recommendations\n1. Add comprehensive error handling...\n2. Implement session refresh logic...\n"
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "VALIDATION_ERROR",
                            "INVALID_PR_FORMAT",
                            "NO_REPOSITORY"
                          ]
                        },
                        "message": {
                          "type": "string"
                        },
                        "details": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenError"
          },
          "404": {
            "description": "Project, requirement, or PR not found"
          },
          "499": {
            "description": "Request aborted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "REQUEST_ABORTED"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Service health check",
        "description": "Returns basic information about the review acceptance service",
        "tags": [
          "Review"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or short ID (PROJ-123)"
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Requirement UUID or short ID (REQ-123)"
          }
        ],
        "responses": {
          "200": {
            "description": "Service information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "endpoint": {
                      "type": "string"
                    },
                    "methods": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "description": {
                      "type": "string"
                    },
                    "requirements": {
                      "type": "string"
                    },
                    "inputs": {
                      "type": "object"
                    },
                    "streaming": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}": {
      "get": {
        "summary": "Get requirement details",
        "description": "Retrieves detailed information about a specific requirement",
        "tags": [
          "Projects",
          "Requirements"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "excludeDesigns",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "When true, omit injected designs from the returned content"
          }
        ],
        "responses": {
          "200": {
            "description": "Requirement details retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "short_id": {
                      "type": "string",
                      "description": "Human-readable ID (e.g., \"REQ-123\")"
                    },
                    "name": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "PLANNED",
                        "IN_PROGRESS",
                        "COMPLETED",
                        "CANCELLED",
                        "REVIEW",
                        "IDEA"
                      ]
                    },
                    "complexity": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "readiness": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "assigned_to": {
                      "type": "string",
                      "format": "uuid",
                      "nullable": true
                    },
                    "branch": {
                      "type": "string",
                      "nullable": true,
                      "description": "The Git branch associated with this requirement",
                      "example": "feature/add-user-auth"
                    },
                    "url": {
                      "type": "string",
                      "nullable": true,
                      "description": "Deep-link URL to the requirement in the BrainGrid app",
                      "example": "https://app.braingrid.ai/projects/PROJ-2/requirements/REQ-42"
                    },
                    "assignee": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "first_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "last_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "email": {
                          "type": "string",
                          "format": "email"
                        }
                      }
                    },
                    "content": {
                      "type": "string",
                      "nullable": true
                    },
                    "tasks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "number": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "PLANNED",
                              "IN_PROGRESS",
                              "COMPLETED",
                              "CANCELLED"
                            ]
                          },
                          "complexity": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5
                          },
                          "readiness": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5
                          },
                          "assigned_to": {
                            "type": "string",
                            "format": "uuid",
                            "nullable": true
                          },
                          "blocked_by": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "started_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "finished_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completed_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    }
                  }
                },
                "example": {
                  "id": "550e8400-e29b-41d4-a716-446655440000",
                  "short_id": "REQ-42",
                  "name": "Implement user authentication",
                  "status": "IN_PROGRESS",
                  "complexity": 3,
                  "readiness": 4,
                  "assigned_to": "user-uuid-123",
                  "branch": "feature/add-user-auth",
                  "assignee": {
                    "id": "user-uuid-123",
                    "first_name": "Jane",
                    "last_name": "Doe",
                    "email": "jane@example.com"
                  },
                  "content": "Implement OAuth 2.0 authentication flow with social providers",
                  "tasks": [
                    {
                      "id": "task-uuid-1",
                      "number": "1",
                      "title": "Set up OAuth provider configuration",
                      "status": "COMPLETED",
                      "complexity": 2,
                      "readiness": 5,
                      "assigned_to": null,
                      "blocked_by": [],
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-16T14:22:00Z",
                      "started_at": "2024-01-15T11:00:00Z",
                      "finished_at": "2024-01-16T14:22:00Z"
                    },
                    {
                      "id": "task-uuid-2",
                      "number": "2",
                      "title": "Implement callback handler",
                      "status": "IN_PROGRESS",
                      "complexity": 3,
                      "readiness": 4,
                      "assigned_to": null,
                      "blocked_by": [
                        "1"
                      ],
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-17T09:15:00Z",
                      "started_at": "2024-01-17T09:15:00Z",
                      "finished_at": null
                    }
                  ],
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-20T14:22:00Z",
                  "started_at": "2024-01-16T09:00:00Z",
                  "completed_at": null
                }
              }
            }
          },
          "404": {
            "description": "Requirement not found"
          }
        }
      },
      "patch": {
        "summary": "Update requirement",
        "description": "Updates requirement properties",
        "tags": [
          "Projects",
          "Requirements"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "complexity": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "readiness": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "PLANNED",
                      "IN_PROGRESS",
                      "COMPLETED",
                      "CANCELLED",
                      "REVIEW",
                      "IDEA"
                    ]
                  },
                  "content": {
                    "type": "string",
                    "maxLength": 100000,
                    "description": "Full markdown body of the requirement"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Requirement updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "short_id": {
                      "type": "string",
                      "description": "Human-readable ID (e.g., \"REQ-123\")"
                    },
                    "name": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "PLANNED",
                        "IN_PROGRESS",
                        "COMPLETED",
                        "CANCELLED",
                        "REVIEW",
                        "IDEA"
                      ]
                    },
                    "complexity": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "readiness": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "assigned_to": {
                      "type": "string",
                      "format": "uuid",
                      "nullable": true
                    },
                    "branch": {
                      "type": "string",
                      "nullable": true,
                      "description": "The Git branch associated with this requirement",
                      "example": "feature/add-user-auth"
                    },
                    "url": {
                      "type": "string",
                      "nullable": true,
                      "description": "Deep-link URL to the requirement in the BrainGrid app",
                      "example": "https://app.braingrid.ai/projects/PROJ-2/requirements/REQ-42"
                    },
                    "assignee": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "first_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "last_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "email": {
                          "type": "string",
                          "format": "email"
                        }
                      }
                    },
                    "content": {
                      "type": "string",
                      "nullable": true
                    },
                    "tasks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "number": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "PLANNED",
                              "IN_PROGRESS",
                              "COMPLETED",
                              "CANCELLED"
                            ]
                          },
                          "complexity": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5
                          },
                          "readiness": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5
                          },
                          "assigned_to": {
                            "type": "string",
                            "format": "uuid",
                            "nullable": true
                          },
                          "blocked_by": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "started_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "finished_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completed_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    }
                  }
                },
                "example": {
                  "id": "550e8400-e29b-41d4-a716-446655440000",
                  "short_id": "REQ-42",
                  "name": "Implement user authentication (Updated)",
                  "status": "IN_PROGRESS",
                  "complexity": 4,
                  "readiness": 5,
                  "assigned_to": "user-uuid-123",
                  "assignee": {
                    "id": "user-uuid-123",
                    "first_name": "Jane",
                    "last_name": "Doe",
                    "email": "jane@example.com"
                  },
                  "content": "Implement OAuth 2.0 authentication flow with social providers",
                  "tasks": [
                    {
                      "id": "task-uuid-1",
                      "number": "1",
                      "title": "Set up OAuth provider configuration",
                      "status": "COMPLETED",
                      "complexity": 2,
                      "readiness": 5,
                      "assigned_to": null,
                      "blocked_by": [],
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-16T14:22:00Z",
                      "started_at": "2024-01-15T11:00:00Z",
                      "finished_at": "2024-01-16T14:22:00Z"
                    }
                  ],
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-21T10:00:00Z",
                  "started_at": "2024-01-16T09:00:00Z",
                  "completed_at": null
                }
              }
            }
          },
          "404": {
            "description": "Requirement not found"
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "field": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "code": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}/tags/{tagName}": {
      "delete": {
        "summary": "Remove a tag from a requirement",
        "description": "Removes the association between a tag and a requirement. The tag remains in the organization.",
        "tags": [
          "Requirements",
          "Tags"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (PROJ-XXX or UUID)"
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Requirement ID (REQ-XXX or UUID)"
          },
          {
            "in": "path",
            "name": "tagName",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Tag name to remove",
            "example": "urgent"
          }
        ],
        "responses": {
          "204": {
            "description": "Tag removed successfully (no content)"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Tag not found, requirement not found, or tag not associated with requirement",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "tagNotFound": {
                    "value": {
                      "error": "Tag with name 'nonexistent' not found",
                      "code": "TAG_NOT_FOUND"
                    }
                  },
                  "associationNotFound": {
                    "value": {
                      "error": "Tag association not found for this requirement",
                      "code": "ASSOCIATION_NOT_FOUND"
                    }
                  },
                  "requirementNotFound": {
                    "value": {
                      "error": "Requirement not found in this project",
                      "code": "REQUIREMENT_NOT_FOUND"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}/tags": {
      "get": {
        "summary": "List tags for a requirement",
        "description": "Retrieves all tags associated with a specific requirement",
        "tags": [
          "Requirements",
          "Tags"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (PROJ-XXX or UUID)"
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Requirement ID (REQ-XXX or UUID)"
          }
        ],
        "responses": {
          "200": {
            "description": "List of tags retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "name": {
                        "type": "string"
                      },
                      "color": {
                        "type": "string",
                        "nullable": true
                      },
                      "organization_id": {
                        "type": "string",
                        "format": "uuid",
                        "nullable": true
                      },
                      "created_at": {
                        "type": "string",
                        "format": "date-time"
                      },
                      "updated_at": {
                        "type": "string",
                        "format": "date-time",
                        "nullable": true
                      }
                    }
                  }
                },
                "example": [
                  {
                    "id": "550e8400-e29b-41d4-a716-446655440000",
                    "name": "urgent",
                    "color": "#FF0000",
                    "organization_id": "org-uuid-123",
                    "created_at": "2024-01-15T10:30:00Z",
                    "updated_at": "2024-01-15T10:30:00Z"
                  },
                  {
                    "id": "550e8400-e29b-41d4-a716-446655440001",
                    "name": "bug",
                    "color": "#FFA500",
                    "organization_id": "org-uuid-123",
                    "created_at": "2024-01-16T14:22:00Z",
                    "updated_at": "2024-01-16T14:22:00Z"
                  }
                ]
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Requirement not found"
          }
        }
      },
      "post": {
        "summary": "Add a tag to a requirement",
        "description": "Associates a tag with a requirement. Creates the tag if it doesn't exist in the organization. Maximum 5 tags per requirement.",
        "tags": [
          "Requirements",
          "Tags"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (PROJ-XXX or UUID)"
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Requirement ID (REQ-XXX or UUID)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "color"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Tag name",
                    "example": "urgent"
                  },
                  "color": {
                    "type": "string",
                    "pattern": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",
                    "description": "Hex color code",
                    "example": "#FF0000"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Tag added successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "artifact_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "tag_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "tag": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "name": {
                          "type": "string"
                        },
                        "color": {
                          "type": "string",
                          "nullable": true
                        },
                        "organization_id": {
                          "type": "string",
                          "format": "uuid",
                          "nullable": true
                        },
                        "created_at": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "updated_at": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        }
                      }
                    },
                    "requirement": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "name": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "example": {
                  "id": "cuid123",
                  "artifact_id": "550e8400-e29b-41d4-a716-446655440000",
                  "tag_id": "550e8400-e29b-41d4-a716-446655440001",
                  "created_at": "2024-01-15T10:30:00Z",
                  "tag": {
                    "id": "550e8400-e29b-41d4-a716-446655440001",
                    "name": "urgent",
                    "color": "#FF0000",
                    "organization_id": "org-uuid-123",
                    "created_at": "2024-01-15T10:30:00Z",
                    "updated_at": "2024-01-15T10:30:00Z"
                  },
                  "requirement": {
                    "id": "550e8400-e29b-41d4-a716-446655440000",
                    "name": "Implement user authentication"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request body"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Requirement not found"
          },
          "422": {
            "description": "Validation error (max tags limit, duplicate tag, invalid color)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "maxTags": {
                    "value": {
                      "error": "Cannot add more than 5 tags to a requirement. Please remove a tag first.",
                      "code": "MAX_TAGS_EXCEEDED"
                    }
                  },
                  "duplicate": {
                    "value": {
                      "error": "Tag is already associated with this requirement",
                      "code": "DUPLICATE_TAG"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}/tasks/{taskId}": {
      "get": {
        "summary": "Get task details",
        "description": "Retrieves details for a specific task",
        "tags": [
          "Projects",
          "Requirements",
          "Tasks"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                },
                "example": {
                  "id": "task-uuid-1",
                  "number": "1",
                  "title": "Set up OAuth provider configuration",
                  "content": "Configure OAuth 2.0 provider settings for Google and GitHub",
                  "status": "COMPLETED",
                  "assigned_to": null,
                  "blocked_by": [],
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-16T14:22:00Z",
                  "started_at": "2024-01-15T11:00:00Z",
                  "finished_at": "2024-01-16T14:22:00Z"
                }
              }
            }
          },
          "404": {
            "description": "Task not found"
          }
        }
      },
      "patch": {
        "summary": "Update task",
        "description": "Updates task properties including title, content, status, assignments, and dependencies",
        "tags": [
          "Projects",
          "Requirements",
          "Tasks"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "content": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "PLANNED",
                      "IN_PROGRESS",
                      "COMPLETED",
                      "CANCELLED"
                    ]
                  },
                  "assigned_to": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  },
                  "blocked_by": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                },
                "example": {
                  "id": "task-uuid-2",
                  "number": "2",
                  "title": "Implement callback handler",
                  "content": "Create OAuth callback endpoint and token exchange logic",
                  "status": "IN_PROGRESS",
                  "assigned_to": null,
                  "blocked_by": [
                    "1"
                  ],
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-17T09:15:00Z",
                  "started_at": "2024-01-17T09:15:00Z",
                  "finished_at": null
                }
              }
            }
          },
          "404": {
            "description": "Task not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      },
      "delete": {
        "summary": "Delete task",
        "description": "Deletes a task if it doesn't block any other tasks",
        "tags": [
          "Projects",
          "Requirements",
          "Tasks"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "taskId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Task deleted successfully"
          },
          "404": {
            "description": "Task not found"
          },
          "409": {
            "description": "Cannot delete task that blocks other tasks"
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements/{requirementId}/tasks": {
      "get": {
        "summary": "List requirement tasks",
        "description": "Lists all tasks for a specific requirement with pagination",
        "tags": [
          "Projects",
          "Requirements",
          "Tasks"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tasks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Task"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                },
                "example": {
                  "tasks": [
                    {
                      "id": "task-uuid-1",
                      "number": "1",
                      "title": "Set up OAuth provider configuration",
                      "content": "Configure OAuth 2.0 provider settings for Google and GitHub",
                      "status": "COMPLETED",
                      "assigned_to": null,
                      "blocked_by": [],
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-16T14:22:00Z",
                      "started_at": "2024-01-15T11:00:00Z",
                      "finished_at": "2024-01-16T14:22:00Z"
                    },
                    {
                      "id": "task-uuid-2",
                      "number": "2",
                      "title": "Implement callback handler",
                      "content": "Create OAuth callback endpoint and token exchange logic",
                      "status": "IN_PROGRESS",
                      "assigned_to": null,
                      "blocked_by": [
                        "1"
                      ],
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-17T09:15:00Z",
                      "started_at": "2024-01-17T09:15:00Z",
                      "finished_at": null
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 50,
                    "total": 2,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "404": {
            "description": "Requirement not found"
          }
        }
      },
      "post": {
        "summary": "Create task",
        "description": "Creates a new task for a requirement",
        "tags": [
          "Projects",
          "Requirements",
          "Tasks"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "requirementId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title",
                  "content"
                ],
                "properties": {
                  "title": {
                    "type": "string"
                  },
                  "content": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Task created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Task"
                },
                "example": {
                  "id": "task-uuid-3",
                  "number": "3",
                  "title": "Add session management",
                  "content": "Implement session storage and refresh token logic",
                  "status": "PLANNED",
                  "assigned_to": null,
                  "blocked_by": [
                    "2"
                  ],
                  "created_at": "2024-01-18T10:00:00Z",
                  "updated_at": "2024-01-18T10:00:00Z",
                  "started_at": null,
                  "finished_at": null
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "field": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "code": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}/requirements": {
      "get": {
        "summary": "List requirements for a project",
        "description": "Lists requirements for a specific project with pagination",
        "tags": [
          "Projects",
          "Requirements"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "tags",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated tag names to filter by (AND logic). Example \"urgent,bug\" returns requirements with both tags.",
            "example": "urgent,bug"
          }
        ],
        "responses": {
          "200": {
            "description": "Requirements retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requirements": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "short_id": {
                            "type": "string",
                            "description": "Human-readable ID (e.g., \"REQ-123\")"
                          },
                          "name": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "PLANNED",
                              "IN_PROGRESS",
                              "COMPLETED",
                              "CANCELLED"
                            ]
                          },
                          "complexity": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5,
                            "nullable": true
                          },
                          "readiness": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5,
                            "nullable": true
                          },
                          "assigned_to": {
                            "type": "string",
                            "format": "uuid",
                            "nullable": true
                          },
                          "branch": {
                            "type": "string",
                            "nullable": true,
                            "description": "The Git branch associated with this requirement",
                            "example": "feature/add-user-auth"
                          },
                          "url": {
                            "type": "string",
                            "nullable": true,
                            "description": "Deep-link URL to the requirement in the BrainGrid app",
                            "example": "https://app.braingrid.ai/projects/PROJ-2/requirements/REQ-42"
                          },
                          "assignee": {
                            "type": "object",
                            "nullable": true,
                            "properties": {
                              "id": {
                                "type": "string",
                                "format": "uuid"
                              },
                              "first_name": {
                                "type": "string",
                                "nullable": true
                              },
                              "last_name": {
                                "type": "string",
                                "nullable": true
                              },
                              "email": {
                                "type": "string",
                                "format": "email"
                              }
                            }
                          },
                          "task_progress": {
                            "type": "object",
                            "properties": {
                              "total": {
                                "type": "integer",
                                "minimum": 0
                              },
                              "completed": {
                                "type": "integer",
                                "minimum": 0
                              },
                              "progress_percentage": {
                                "type": "number",
                                "minimum": 0,
                                "maximum": 100
                              }
                            }
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "started_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "completed_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                },
                "example": {
                  "requirements": [
                    {
                      "id": "550e8400-e29b-41d4-a716-446655440000",
                      "short_id": "REQ-42",
                      "name": "Implement user authentication",
                      "status": "IN_PROGRESS",
                      "complexity": 3,
                      "readiness": 4,
                      "assigned_to": "user-uuid-123",
                      "branch": "feature/add-user-auth",
                      "assignee": {
                        "id": "user-uuid-123",
                        "first_name": "Jane",
                        "last_name": "Doe",
                        "email": "jane@example.com"
                      },
                      "task_progress": {
                        "total": 10,
                        "completed": 6,
                        "progress_percentage": 60
                      },
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-20T14:22:00Z",
                      "started_at": "2024-01-16T09:00:00Z",
                      "completed_at": null
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 50,
                    "total": 42,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "post": {
        "summary": "Create requirement in project",
        "description": "Creates a new requirement within a specific project",
        "tags": [
          "Projects",
          "Requirements"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "complexity": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "readiness": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 5
                  },
                  "content": {
                    "type": "string",
                    "nullable": true
                  },
                  "assigned_to": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Requirement created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "short_id": {
                      "type": "string",
                      "description": "Human-readable ID (e.g., \"REQ-123\")"
                    },
                    "name": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "PLANNED",
                        "IN_PROGRESS",
                        "COMPLETED",
                        "CANCELLED"
                      ]
                    },
                    "complexity": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "readiness": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "assigned_to": {
                      "type": "string",
                      "format": "uuid",
                      "nullable": true
                    },
                    "branch": {
                      "type": "string",
                      "nullable": true,
                      "description": "The Git branch associated with this requirement",
                      "example": "feature/add-user-auth"
                    },
                    "url": {
                      "type": "string",
                      "nullable": true,
                      "description": "Deep-link URL to the requirement in the BrainGrid app",
                      "example": "https://app.braingrid.ai/projects/PROJ-2/requirements/REQ-42"
                    },
                    "assignee": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "first_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "last_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "email": {
                          "type": "string",
                          "format": "email"
                        }
                      }
                    },
                    "content": {
                      "type": "string",
                      "nullable": true
                    },
                    "tasks": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "number": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string",
                            "enum": [
                              "PLANNED",
                              "IN_PROGRESS",
                              "COMPLETED",
                              "CANCELLED"
                            ]
                          },
                          "complexity": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5
                          },
                          "readiness": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 5
                          },
                          "assigned_to": {
                            "type": "string",
                            "format": "uuid",
                            "nullable": true
                          },
                          "blocked_by": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "updated_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "started_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          },
                          "finished_at": {
                            "type": "string",
                            "format": "date-time",
                            "nullable": true
                          }
                        }
                      }
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completed_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    }
                  }
                },
                "example": {
                  "id": "550e8400-e29b-41d4-a716-446655440000",
                  "short_id": "REQ-42",
                  "name": "Implement user authentication",
                  "status": "PLANNED",
                  "complexity": 3,
                  "readiness": 4,
                  "assigned_to": "user-uuid-123",
                  "branch": null,
                  "assignee": {
                    "id": "user-uuid-123",
                    "first_name": "Jane",
                    "last_name": "Doe",
                    "email": "jane@example.com"
                  },
                  "content": "Implement OAuth 2.0 authentication flow with social providers",
                  "tasks": [],
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-15T10:30:00Z",
                  "started_at": null,
                  "completed_at": null
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "field": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "code": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/v1/projects/{projectId}": {
      "get": {
        "summary": "Get project by ID",
        "description": "Retrieves a specific project by UUID or short ID",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project UUID or short ID (PROJ-123)"
          }
        ],
        "responses": {
          "200": {
            "description": "Project retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                },
                "example": {
                  "id": "550e8400-e29b-41d4-a716-446655440000",
                  "short_id": "PROJ-15",
                  "name": "Mobile App Redesign",
                  "description": "Q1 2024 mobile application redesign project",
                  "repository": {
                    "id": "repo-uuid-1",
                    "owner": "braingrid",
                    "name": "mobile-app"
                  },
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-20T14:22:00Z"
                }
              }
            }
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "patch": {
        "summary": "Update project",
        "description": "Updates project name, description, and/or associates a repository. Repository can only be set once (when currently null).",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000,
                    "nullable": true
                  },
                  "repository_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Repository UUID to associate with or change on the project"
                  },
                  "designs_enabled": {
                    "type": "boolean",
                    "description": "When false, the planning agent cannot create designs for this project"
                  }
                }
              },
              "example": {
                "name": "Mobile App Redesign (Updated)",
                "description": "Updated description",
                "repository_id": "repo-uuid-1",
                "designs_enabled": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Project updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                },
                "example": {
                  "id": "550e8400-e29b-41d4-a716-446655440000",
                  "short_id": "PROJ-15",
                  "name": "Mobile App Redesign (Updated)",
                  "description": "Updated description",
                  "repository": {
                    "id": "repo-uuid-1",
                    "owner": "braingrid",
                    "name": "mobile-app"
                  },
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-21T10:00:00Z"
                }
              }
            }
          },
          "403": {
            "description": "Repository does not belong to organization"
          },
          "404": {
            "description": "Project or repository not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/sandbox/files/content": {
      "get": {
        "summary": "Read a single file from the build session's sandbox",
        "description": "Returns UTF-8 file contents. Rejects files > 1 MB (413), files that\nsniff as binary in the first 8 KB (415), or paths that escape the\nproject root (400). Path must be relative to the project root.\n",
        "tags": [
          "BuilderCode"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "session",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File contents"
          },
          "400": {
            "description": "Invalid project",
            "session": null,
            "or path": null
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "File not found"
          },
          "409": {
            "description": "Sandbox not running"
          },
          "413": {
            "description": "File too large"
          },
          "415": {
            "description": "File appears to be binary"
          },
          "502": {
            "description": "Upstream sandbox error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/sandbox/files": {
      "get": {
        "summary": "List files in the build session's sandbox",
        "description": "Walks the agent's working directory (`/workspace/{repoName}`) and\nreturns every file + directory inside, minus the standard ignore\nlist (`node_modules`, `.git`, `.next`, `dist`, `build`, `.turbo`,\n`__pycache__`). Reflects the sandbox's live state — including\nin-progress agent edits that haven't been committed.\n",
        "tags": [
          "BuilderCode"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "session",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Build session ID whose sandbox to read from."
          }
        ],
        "responses": {
          "200": {
            "description": "File entries"
          },
          "400": {
            "description": "Invalid project ID or session ID"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Build session not found"
          },
          "409": {
            "description": "Sandbox not running for this session"
          },
          "502": {
            "description": "Upstream sandbox error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/specify": {
      "post": {
        "summary": "Create AI-refined requirement from prompt",
        "description": "Creates a new requirement from a user prompt, refining it with AI assistance.\nThe endpoint creates an initial requirement with the original prompt, then uses\nAI to refine it into a structured requirement with acceptance criteria, implementation\ndetails, and context from linked repositories.\n",
        "tags": [
          "Projects",
          "Requirements"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)",
            "example": "PROJ-42"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "minLength": 10,
                    "maxLength": 5000,
                    "description": "User's requirement description to be refined by AI",
                    "example": "Add OAuth authentication with Google and GitHub providers"
                  }
                }
              },
              "example": {
                "prompt": "Add OAuth authentication with Google and GitHub providers"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Requirement created and refined successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "short_id": {
                      "type": "string",
                      "description": "Human-readable ID (e.g., \"REQ-123\")"
                    },
                    "name": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "PLANNED",
                        "IN_PROGRESS",
                        "COMPLETED",
                        "CANCELLED"
                      ]
                    },
                    "complexity": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "readiness": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 5,
                      "nullable": true
                    },
                    "assigned_to": {
                      "type": "string",
                      "format": "uuid",
                      "nullable": true
                    },
                    "assignee": {
                      "type": "object",
                      "nullable": true,
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "first_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "last_name": {
                          "type": "string",
                          "nullable": true
                        },
                        "email": {
                          "type": "string",
                          "format": "email"
                        }
                      }
                    },
                    "content": {
                      "type": "string",
                      "nullable": true
                    },
                    "tasks": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "completed_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    }
                  }
                },
                "example": {
                  "id": "550e8400-e29b-41d4-a716-446655440000",
                  "short_id": "REQ-42",
                  "name": "Add OAuth authentication with Google and G...",
                  "status": "PLANNED",
                  "complexity": 3,
                  "readiness": 4,
                  "assigned_to": null,
                  "assignee": null,
                  "content": "# OAuth Authentication Implementation\n\n## Overview\nImplement OAuth 2.0...",
                  "tasks": [],
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-15T10:30:15Z",
                  "started_at": null,
                  "completed_at": null
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON in request body",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "402": {
            "description": "Organization is unfunded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "ORG_UNFUNDED"
                      ]
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Organization is suspended",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "enum": [
                        "ORG_SUSPENDED"
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Project not found"
          },
          "408": {
            "description": "Request timeout",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "VALIDATION_ERROR"
                          ]
                        },
                        "message": {
                          "type": "string"
                        },
                        "details": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "499": {
            "description": "Request aborted by client",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "REQUEST_ABORTED"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "Service temporarily unavailable"
          }
        }
      }
    },
    "/v1/projects/{projectId}/supabase-project": {
      "post": {
        "summary": "Provision a Supabase project for a BrainGrid project",
        "description": "Creates a new Supabase project, waits for it to become healthy,\nenables publishable/secret API keys, and stores credentials\nin the project config.\n",
        "tags": [
          "Projects",
          "Supabase"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Supabase project name (should match GitHub repo name)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Supabase project provisioned and credentials stored"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/vercel-project": {
      "post": {
        "summary": "Provision a Vercel project for a BrainGrid project",
        "description": "Creates a new Vercel project in BrainGrid's team, optionally sets\nenvironment variables and adds a custom domain, then stores the\nVercel project reference in the project config.\n",
        "tags": [
          "Projects",
          "Vercel"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Vercel project name (lowercase alphanumeric with hyphens)"
                  },
                  "framework": {
                    "type": "string",
                    "description": "Framework preset (e.g. nextjs, vite)"
                  },
                  "gitRepository": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "github"
                        ]
                      },
                      "repo": {
                        "type": "string",
                        "description": "GitHub repo in \"owner/repo\" format"
                      }
                    }
                  },
                  "environmentVariables": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "key": {
                          "type": "string"
                        },
                        "value": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "domain": {
                    "type": "string",
                    "description": "Optional custom domain to add (in addition to auto-assigned {name}.bgridapp.com)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Vercel project provisioned with auto-domain and reference stored"
          },
          "400": {
            "description": "Invalid request (e.g., malformed JSON, invalid parameters)"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project not found"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workflows/{workflowId}/publish": {
      "post": {
        "summary": "Publish a workflow",
        "description": "Validates the draft graph, freezes it as the live version, and registers its triggers (webhook URL, schedule). Publishing is instant — no rebuild required for graph changes.",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workflow published — returns the workflow with its live version and triggers"
          },
          "400": {
            "description": "Graph not publishable (missing trigger / required fields)"
          },
          "403": {
            "description": "Workflows not available (hosting not provisioned)"
          },
          "404": {
            "description": "Workflow not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workflows/{workflowId}": {
      "get": {
        "summary": "Get a workflow",
        "description": "Returns a workflow with its current draft graph and live version (if published).",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workflow retrieved"
          },
          "403": {
            "description": "Workflows not available (hosting not provisioned)"
          },
          "404": {
            "description": "Workflow not found"
          }
        }
      },
      "patch": {
        "summary": "Update a workflow",
        "description": "Updates a workflow's name/description and/or replaces its draft graph (autosave).",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string",
                    "nullable": true
                  },
                  "graph": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workflow updated"
          },
          "400": {
            "description": "Invalid graph or body"
          },
          "404": {
            "description": "Workflow not found"
          }
        }
      },
      "delete": {
        "summary": "Delete a workflow",
        "description": "Deletes a workflow and all of its versions, runs, and triggers. Organization owners only.",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workflow deleted"
          },
          "403": {
            "description": "Not permitted (owner only) or hosting not provisioned"
          },
          "404": {
            "description": "Workflow not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workflows/{workflowId}/runs/{runId}": {
      "get": {
        "summary": "Get a workflow run with per-step status",
        "description": "Poll while the run is active to stream per-node progress.",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "runId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Run retrieved with steps"
          },
          "404": {
            "description": "Run not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workflows/{workflowId}/runs": {
      "post": {
        "summary": "Start a workflow test run",
        "description": "Runs the current draft graph and streams per-node progress (poll the run detail endpoint). Returns 202 with the queued run.",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "input": {
                    "description": "Optional trigger payload for the run"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Run queued"
          },
          "400": {
            "description": "Graph not runnable (no trigger / no nodes)"
          },
          "402": {
            "description": "Out of credits"
          },
          "403": {
            "description": "Workflows not available"
          }
        }
      },
      "get": {
        "summary": "List workflow runs",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workflowId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Runs retrieved"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workflows/generate": {
      "post": {
        "summary": "Generate a workflow graph from natural language",
        "description": "Describes a goal in plain English and returns a validated workflow graph built from the node catalog. The graph is not saved — apply it via the workflow PATCH endpoint (or it hydrates the canvas in the editor).",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "goal"
                ],
                "properties": {
                  "goal": {
                    "type": "string",
                    "example": "When a Stripe payment succeeds, post to #sales and log it to a sheet"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated graph"
          },
          "400": {
            "description": "Could not generate a valid workflow"
          },
          "402": {
            "description": "Out of credits"
          },
          "403": {
            "description": "Workflows not available"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workflows": {
      "get": {
        "summary": "List workflows for a project",
        "description": "Lists all workflows in a project. Requires the project to have Vercel hosting provisioned.",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workflows retrieved successfully"
          },
          "403": {
            "description": "Workflows not available (hosting not provisioned)"
          }
        }
      },
      "post": {
        "summary": "Create a workflow",
        "description": "Creates a new workflow (with an empty draft graph). Requires Vercel hosting provisioned.",
        "tags": [
          "Workflows"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Workflow created"
          },
          "403": {
            "description": "Workflows not available (hosting not provisioned)"
          },
          "409": {
            "description": "Workflow limit reached"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/artifacts": {
      "get": {
        "summary": "Get related artifacts for a workspace",
        "description": "Returns rich artifact data (EPICs with nested requirements) linked to a workspace.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Related artifacts retrieved successfully"
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or conversation not found"
          }
        }
      },
      "post": {
        "summary": "Link an artifact to a workspace",
        "description": "Associates an existing artifact (requirement or epic) with a workspace.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "artifactId"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string",
                    "description": "Artifact ID (UUID or REQ-XXX / EPIC-XXX format)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Artifact linked to conversation successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, conversation, or artifact not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      },
      "delete": {
        "summary": "Unlink an artifact from a workspace",
        "description": "Removes the association between an artifact and a workspace.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "artifactId"
                ],
                "properties": {
                  "artifactId": {
                    "type": "string",
                    "description": "Artifact ID (UUID or REQ-XXX / EPIC-XXX format)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Artifact unlinked from conversation successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, conversation, or artifact not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/attachments/{attachmentId}/refresh-url": {
      "post": {
        "summary": "Generate a new signed URL for an expired workspace attachment",
        "tags": [
          "WorkspaceAttachments"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "attachmentId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Attachment ID"
          }
        ],
        "responses": {
          "200": {
            "description": "New signed URL generated"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Attachment not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/attachments/{attachmentId}": {
      "delete": {
        "summary": "Delete a workspace attachment",
        "tags": [
          "WorkspaceAttachments"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "attachmentId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Attachment ID"
          }
        ],
        "responses": {
          "204": {
            "description": "Attachment deleted"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Attachment not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/attachments": {
      "get": {
        "summary": "List file attachments for a workspace",
        "tags": [
          "WorkspaceAttachments"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "List of workspace attachments"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          }
        }
      },
      "post": {
        "summary": "Upload a file attachment to a workspace",
        "tags": [
          "WorkspaceAttachments"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "File uploaded successfully"
          },
          "400": {
            "description": "Invalid file type or missing file"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "413": {
            "description": "File too large"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/attempts": {
      "get": {
        "summary": "List publish attempts for a workspace",
        "description": "Returns the most recent publish attempts for a workspace, plus\nthe latest one separately. Used by the UI to render publish\nstatus (e.g., show the latest attempt's failure_message when the\nworkspace is in PUBLISH_FAILED) and the resume affordance for\nPUBLISH_CONFLICT.\n",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List + latest"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/build-sessions/{sessionId}/debug": {
      "get": {
        "summary": "Get build session diagnostics",
        "tags": [
          "BuildSessions"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Build session diagnostics including frontend/backend state and anomalies"
          },
          "404": {
            "description": "Session not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/build-sessions/{sessionId}/events": {
      "get": {
        "summary": "Poll events for a build session",
        "description": "Returns events for a build session after the specified sequence number.\nSupports cursor-based polling where the client tracks the last seen seq\nand requests new events on each poll.\n",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Build session ID"
          },
          {
            "in": "query",
            "name": "after",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Return events after this sequence number"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            },
            "description": "Maximum number of events to return"
          }
        ],
        "responses": {
          "200": {
            "description": "Events retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "session_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "seq": {
                            "type": "integer"
                          },
                          "event_type": {
                            "type": "string"
                          },
                          "payload": {
                            "type": "object"
                          },
                          "created_at": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "latestSeq": {
                      "type": "integer",
                      "description": "The highest sequence number in the returned events (0 if no events)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/build-sessions/{sessionId}/messages": {
      "post": {
        "summary": "Send a user message to an active build session",
        "description": "Sends a user message to an active build session. The message is\ndispatched to the Claude agent running in the sandbox via\nsendMessageStreaming. Returns immediately with a success indicator;\npoll the events endpoint for streaming output.\n",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Build session ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "content"
                ],
                "properties": {
                  "content": {
                    "type": "string",
                    "description": "The user message to send to the build agent"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message dispatched successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or session not found"
          },
          "409": {
            "description": "Session is not active"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/build-sessions/{sessionId}": {
      "get": {
        "summary": "Get build session detail",
        "description": "Returns the full details of a specific build session.",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Build session ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Build session retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BuildSessionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or session not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "summary": "Cancel a build session",
        "description": "Cancels an active build session. Destroys the associated sandbox\nand sets the session status to CANCELLED.\n",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Build session ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Build session cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or session not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/build-sessions/{sessionId}/stop": {
      "post": {
        "summary": "Stop the current agent turn without terminating the session",
        "description": "Stops the active agent turn and transitions the session from BUILDING\nto IDLE. The sandbox stays alive for follow-up messages. The running\nClaude process finishes naturally but its output is no longer consumed.\n",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Build session ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Turn stopped successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or session not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/build-sessions": {
      "post": {
        "summary": "Create a new build session",
        "description": "Creates a new build session for the specified artifact within a project.\nThe session is created in PENDING status and initialization begins\nasynchronously (sandbox creation, credential injection, etc.).\n",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "artifactId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "The requirement or epic artifact ID to build (optional if workspaceId is provided)"
                  },
                  "authMode": {
                    "type": "string",
                    "enum": [
                      "platform",
                      "byok"
                    ],
                    "default": "platform",
                    "description": "Authentication mode for AI provider access"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SSE stream of build session initialization progress",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Server-Sent Events stream. Events are JSON with a \"type\" field:\n- session: Initial session data\n- progress: { step: string } — setup step description\n- done: { session: BuildSessionResponse } — initialization complete\n- error: { error: string } — initialization failed\n"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          },
          "409": {
            "description": "Active build session already exists for this artifact"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "get": {
        "summary": "List build sessions for a workspace",
        "description": "Returns all build sessions for the specified workspace, ordered by creation date descending.",
        "tags": [
          "Projects",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Build sessions retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BuildSessionResponse"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/confirm-publish": {
      "post": {
        "summary": "Confirm or reject a workspace deployment",
        "description": "Called after the frontend has polled deployment status to a terminal state. On success, transitions PUBLISHING → PUBLISHED. On failure, transitions PUBLISHING → ACTIVE.\n",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "outcome"
                ],
                "properties": {
                  "outcome": {
                    "type": "string",
                    "enum": [
                      "success",
                      "failed"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Workspace state updated"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "409": {
            "description": "Invalid state transition (workspace not in PUBLISHING state)"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/deployment-status": {
      "get": {
        "summary": "Check deployment status for a workspace",
        "description": "Polls Vercel deployment status, optionally filtered by commit SHA.",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "commitSha",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Git commit SHA to track specific deployment"
          }
        ],
        "responses": {
          "200": {
            "description": "Deployment status"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/devserver-restart": {
      "post": {
        "summary": "Restart the dev server in a workspace sandbox",
        "description": "Proxies a restart command to the sandbox sidecar. Returns success or an error if the sandbox or session is not found.\n",
        "tags": [
          "Projects",
          "Workspaces",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dev server restarted successfully"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Workspace, session, or sandbox not found"
          },
          "500": {
            "description": "Restart failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/devserver-status": {
      "get": {
        "summary": "Get dev server status for a workspace sandbox",
        "description": "Proxies to the sandbox sidecar to check whether the dev server is running. Returns process details when running, or { running: false }.\n",
        "tags": [
          "Projects",
          "Workspaces",
          "Builder"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dev server status"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Workspace, session, or sandbox not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/has-changes": {
      "get": {
        "summary": "Check if workspace branch has changes",
        "description": "Compares the workspace branch against the default branch to determine if there are commits to publish.",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Branch comparison result"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "502": {
            "description": "GitHub API error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/mark-published": {
      "post": {
        "summary": "Mark a self-managed workspace as published",
        "description": "For projects backed by a self-managed GitHub repository, transitions the workspace directly from BUILDING to PUBLISHED without running the BrainGrid publish pipeline (no PR, no merge, no Vercel provisioning). Rejected with 400 if the repository is not self-managed.\n",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace marked as PUBLISHED"
          },
          "400": {
            "description": "Workspace is not backed by a self-managed repository"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "409": {
            "description": "Invalid state transition"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/plan": {
      "get": {
        "summary": "Get the project plan for a workspace",
        "description": "Returns the project plan scoped to a workspace — EPICs with nested requirements, orphan requirements, blocked_by as short IDs, and computed next_action for each artifact.\n",
        "tags": [
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-N)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N)"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace plan with epics and requirements"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Project or workspace not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/planning-sessions/{sessionId}/events": {
      "get": {
        "summary": "Poll events for a planning session",
        "description": "Returns all event types (content, message, turn_completed, error, etc.)\nfor a planning session after the specified sequence number. Used for\ncatch-up polling by the Realtime client hook after (re)connect.\n",
        "tags": [
          "Projects",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          },
          {
            "in": "query",
            "name": "afterSeq",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Return events after this sequence number"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            },
            "description": "Maximum number of events to return"
          }
        ],
        "responses": {
          "200": {
            "description": "Events retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "latestSeq": {
                      "type": "integer"
                    },
                    "sessionStatus": {
                      "type": "string",
                      "enum": [
                        "ACTIVE",
                        "STREAMING",
                        "COMPLETED",
                        "CANCELLED"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Resource not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/planning-sessions/{sessionId}/messages": {
      "post": {
        "summary": "Add a message to a planning session",
        "description": "Adds a new message to a planning session within a workspace.",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "role",
                  "content"
                ],
                "properties": {
                  "role": {
                    "type": "string",
                    "description": "The role of the message author (e.g. user, assistant)"
                  },
                  "content": {
                    "description": "The message content (any JSON value)"
                  },
                  "tokenCount": {
                    "type": "integer",
                    "description": "Optional token count for the message"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Optional metadata key-value pairs"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Message added successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, conversation, or planning session not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      },
      "get": {
        "summary": "Get messages for a planning session",
        "description": "Returns messages for a planning session using cursor-based pagination.",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          },
          {
            "in": "query",
            "name": "afterSeq",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Return messages with seq greater than this value"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            },
            "description": "Maximum number of messages to return"
          }
        ],
        "responses": {
          "200": {
            "description": "Messages retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "messages": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "latestSeq": {
                      "type": "integer",
                      "description": "The seq of the last message in the result set"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, conversation, or planning session not found"
          }
        }
      },
      "delete": {
        "summary": "Delete a message and all subsequent messages from a planning session",
        "description": "Truncates the planning session message history from the specified message onward. Only user messages can be deleted. All messages at or after the target message's sequence number are removed.\n",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "messageId"
                ],
                "properties": {
                  "messageId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "ID of the message to delete (and all after it)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Messages deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "messagesRemoved": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, workspace, session, or message not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/planning-sessions/{sessionId}": {
      "get": {
        "summary": "Get a planning session with messages",
        "description": "Returns the details of a specific planning session along with its messages.",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Planning session retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "object",
                      "description": "The planning session"
                    },
                    "messages": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "A planning session message"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, conversation, or planning session not found"
          }
        }
      },
      "patch": {
        "summary": "Update a planning session",
        "description": "Updates the status and/or title of a planning session.",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "COMPLETED",
                      "CANCELLED"
                    ],
                    "description": "New status for the planning session"
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "New title for the planning session"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Planning session updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "object",
                      "description": "The updated planning session"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project, conversation, or planning session not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/planning-sessions/{sessionId}/stop": {
      "post": {
        "summary": "Stop the current agent turn in a planning session",
        "description": "Stops the active agent turn and transitions the session from STREAMING\nto ACTIVE. The running agent detects this status change via polling and\naborts. A turn_completed event is written so Realtime clients terminate\ncleanly.\n",
        "tags": [
          "Projects",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          },
          {
            "in": "path",
            "name": "sessionId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Planning session ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Turn stopped successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or session not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/planning-sessions": {
      "post": {
        "summary": "Create a planning session",
        "description": "Creates a new planning session within a workspace.",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Optional title for the planning session"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Planning session created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "object",
                      "description": "The created planning session"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or conversation not found"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      },
      "get": {
        "summary": "List planning sessions for a workspace",
        "description": "Returns all planning sessions associated with a workspace, ordered by creation date descending.",
        "tags": [
          "Projects",
          "Conversations",
          "Planning"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Planning sessions retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "sessions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "description": "A planning session"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or conversation not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/publish-initiated": {
      "post": {
        "summary": "Record a publish-initiated BrainGrid native event",
        "description": "Fires `project.workspace.publish.initiated` when the user clicks publish, regardless of whether the click then opens the publish dialog or the upgrade modal. Used for full-funnel publish analytics.\n",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "trigger",
                  "gated"
                ],
                "properties": {
                  "trigger": {
                    "type": "string",
                    "enum": [
                      "builder_button",
                      "build_progress_cta",
                      "kanban_drag"
                    ]
                  },
                  "gated": {
                    "type": "boolean",
                    "description": "True if the click landed on the upgrade modal (no active sub)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Event recorded"
          },
          "400": {
            "description": "Invalid body or path params"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Workspace not found"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/publish": {
      "post": {
        "summary": "Publish a workspace",
        "description": "Creates a PR, merges it, provisions Vercel hosting, and transitions the workspace to PUBLISHING. Returns commitSha for frontend deployment polling.",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace published successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "409": {
            "description": "Invalid state transition"
          },
          "500": {
            "description": "Publish failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/recover": {
      "post": {
        "summary": "Recover a workspace from PUBLISH_FAILED state",
        "description": "Recovers a workspace from PUBLISH_FAILED (pre-merge GitHub failure) back to BUILDING. Branch is preserved. PUBLISH_FAILED_POST_MERGE is not recoverable in place — clients must create a new workspace instead.",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace recovered successfully"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "409": {
            "description": "Invalid state transition"
          },
          "500": {
            "description": "Recovery failed"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}/resume-publish": {
      "post": {
        "summary": "Resume a publish stuck in PUBLISH_CONFLICT",
        "description": "Called after the user resolves a merge conflict on GitHub.\nTransitions the in-flight `publish_attempts` row from MERGE_CONFLICT\nback to AWAITING_MERGE, and the workspace mirror from PUBLISH_CONFLICT\nback to BUILDING. The frontend then calls /publish again to continue.\n",
        "tags": [
          "Projects",
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace transitioned back to BUILDING"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or workspace not found"
          },
          "409": {
            "description": "No in-flight attempt or attempt not in MERGE_CONFLICT"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces/{workspaceId}": {
      "get": {
        "summary": "Get a workspace by ID",
        "description": "Returns a single workspace with its associated artifacts. Supports both UUID and WKSP-N format.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Conversation retrieved successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or conversation not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "patch": {
        "summary": "Update a workspace",
        "description": "Updates workspace fields such as status or git branch. Supports both UUID and WKSP-N format.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string",
                    "enum": [
                      "PLANNING",
                      "BUILDING",
                      "ARCHIVED"
                    ]
                  },
                  "git_branch": {
                    "type": "string",
                    "maxLength": 255,
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Conversation updated successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or conversation not found"
          },
          "422": {
            "description": "Validation failed"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      },
      "delete": {
        "summary": "Delete a workspace",
        "description": "Permanently deletes a workspace. Supports both UUID and WKSP-N format.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "path",
            "name": "workspaceId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workspace ID (UUID or WKSP-N format)"
          }
        ],
        "responses": {
          "200": {
            "description": "Conversation deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project or conversation not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/v1/projects/{projectId}/workspaces": {
      "post": {
        "summary": "Create a new conversation",
        "description": "Creates a new workspace within a project. Generates a unique WKSP-N short ID.\nAutomatically creates a git branch `{username}/{WKSP-N}` from the project's default branch\nand stores it on the conversation record. Branch creation is non-fatal.\n",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          }
        ],
        "responses": {
          "201": {
            "description": "Conversation created successfully"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          }
        }
      },
      "get": {
        "summary": "List conversations for a project",
        "description": "Returns conversations for a project, optionally filtered by status.",
        "tags": [
          "Projects",
          "Conversations"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "projectId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Project ID (UUID or PROJ-XXX format)"
          },
          {
            "in": "query",
            "name": "status",
            "schema": {
              "type": "string",
              "enum": [
                "ACTIVE",
                "ARCHIVED",
                "PUBLISHING",
                "PUBLISHED",
                "PUBLISH_FAILED",
                "PUBLISH_FAILED_POST_MERGE"
              ]
            },
            "description": "Filter by conversation status"
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 50
            },
            "description": "Maximum number of conversations to return"
          },
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Number of conversations to skip"
          }
        ],
        "responses": {
          "200": {
            "description": "Conversations retrieved successfully"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "404": {
            "description": "Project not found"
          }
        }
      }
    },
    "/v1/projects": {
      "get": {
        "summary": "List projects",
        "description": "Lists projects for the authenticated organization with pagination.\nSupports filtering by repository owner/name.\n",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "in": "query",
            "name": "repository_owner",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "repository_name",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Projects retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "projects": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Project"
                      }
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                },
                "example": {
                  "projects": [
                    {
                      "id": "550e8400-e29b-41d4-a716-446655440000",
                      "short_id": "PROJ-1",
                      "name": "Mobile App",
                      "description": "iOS and Android mobile application",
                      "repository": {
                        "id": "repo-uuid-1",
                        "owner": "braingrid",
                        "name": "mobile-app"
                      },
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-20T14:22:00Z"
                    }
                  ],
                  "pagination": {
                    "page": 1,
                    "limit": 50,
                    "total": 125,
                    "total_pages": 3
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          }
        }
      },
      "post": {
        "summary": "Create a new project",
        "description": "Creates a new project in the authenticated user's organization",
        "tags": [
          "Projects"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000,
                    "nullable": true
                  },
                  "repository_id": {
                    "type": "string",
                    "format": "uuid",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Project created successfully"
          },
          "400": {
            "description": "Validation error"
          },
          "402": {
            "description": "Quota exceeded"
          },
          "409": {
            "description": "Duplicate project name"
          },
          "422": {
            "description": "Validation failed"
          }
        }
      }
    },
    "/v1/repositories/{repositoryId}": {
      "get": {
        "summary": "Get repository details",
        "description": "Retrieves details for a specific GitHub repository",
        "tags": [
          "Repositories"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "repositoryId",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Repository UUID or short ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Repository retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Repository"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "short_id": {
                          "type": "string",
                          "description": "Human-readable ID (e.g., \"REPO-123\")"
                        },
                        "last_synced_at": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        }
                      }
                    }
                  ]
                },
                "example": {
                  "id": "repo-uuid-1",
                  "short_id": "REPO-1",
                  "owner": "braingrid",
                  "name": "backend-api",
                  "full_name": "braingrid/backend-api",
                  "description": "Backend API service",
                  "html_url": "https://github.com/braingrid/backend-api",
                  "is_private": true,
                  "default_branch": "main",
                  "created_at": "2024-01-15T10:30:00Z",
                  "updated_at": "2024-01-20T14:22:00Z",
                  "last_synced_at": "2024-01-20T14:22:00Z"
                }
              }
            }
          },
          "404": {
            "description": "Repository not found"
          }
        }
      }
    },
    "/v1/repositories": {
      "get": {
        "summary": "List repositories",
        "description": "Lists repositories for the authenticated organization, merging database repos with OAuth-connected GitHub repos. Deduplicates by GitHub repository ID.",
        "tags": [
          "Repositories"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "owner",
            "schema": {
              "type": "string"
            },
            "description": "Filter by repository owner (GitHub username or org)"
          },
          {
            "in": "query",
            "name": "name",
            "schema": {
              "type": "string"
            },
            "description": "Filter by repository name (requires owner)"
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            }
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Repositories retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "repositories": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Repository"
                      }
                    },
                    "has_oauth_connection": {
                      "type": "boolean"
                    },
                    "has_github_installation": {
                      "type": "boolean"
                    },
                    "pagination": {
                      "$ref": "#/components/schemas/Pagination"
                    }
                  }
                },
                "example": {
                  "repositories": [
                    {
                      "id": "repo-uuid-1",
                      "github_repository_id": 123456,
                      "name": "backend-api",
                      "full_name": "braingrid/backend-api",
                      "description": "Backend API service",
                      "html_url": "https://github.com/braingrid/backend-api",
                      "private": true,
                      "default_branch": "main",
                      "source": "GITHUB",
                      "creation_method": "GITHUB_APP",
                      "owner": {
                        "login": "braingrid",
                        "avatar_url": "https://avatars.githubusercontent.com/u/1"
                      },
                      "created_at": "2024-01-15T10:30:00Z",
                      "updated_at": "2024-01-20T14:22:00Z"
                    }
                  ],
                  "has_oauth_connection": true,
                  "has_github_installation": true,
                  "pagination": {
                    "page": 1,
                    "limit": 50,
                    "total": 25,
                    "total_pages": 1
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "404": {
            "description": "No repositories found"
          }
        }
      }
    },
    "/v1/review/acceptance": {
      "post": {
        "deprecated": true,
        "summary": "Perform AI code review (DEPRECATED)",
        "description": "**DEPRECATED:** Use `/api/v1/projects/{projectId}/requirements/{requirementId}/review/acceptance` instead.\n\nPerforms AI-powered code reviews on pull requests.\nStreams the review response back to the client in real-time.\n\nThis endpoint will be removed in a future version. Please migrate to the project-scoped endpoint.\n",
        "tags": [
          "Review"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "pullRequestUrl": {
                    "type": "string",
                    "format": "uri",
                    "description": "GitHub pull request URL (required if requirementId not provided)"
                  },
                  "requirementId": {
                    "type": "string",
                    "description": "BrainGrid requirement ID (REQ-XXX or UUID, required if pullRequestUrl not provided)"
                  },
                  "externalDocumentUrl": {
                    "type": "string",
                    "format": "uri",
                    "description": "External document URL for additional context (optional)"
                  },
                  "diff": {
                    "type": "string",
                    "description": "Direct code diff to review (optional, alternative to pullRequestUrl)"
                  }
                }
              },
              "example": {
                "pullRequestUrl": "https://github.com/owner/repo/pull/123",
                "requirementId": "REQ-42"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Streaming review response",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "description": "Real-time streaming response containing the AI-generated code review.\nThe review includes analysis of code changes, acceptance criteria validation,\nand recommendations for improvements.\n"
                },
                "example": "# Code Review for PR #123\n\n## Summary\nThis pull request implements user authentication using OAuth 2.0...\n\n## Acceptance Criteria Review\n✅ OAuth provider configuration implemented\n✅ Callback handler created with token exchange\n⚠️ Session management partially complete\n\n## Code Quality\n- Good separation of concerns\n- Missing error handling in callback endpoint\n- Consider adding rate limiting\n\n## Recommendations\n1. Add comprehensive error handling...\n2. Implement session refresh logic...\n"
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "VALIDATION_ERROR"
                          ]
                        },
                        "message": {
                          "type": "string"
                        },
                        "details": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "code": {
                                "type": "string"
                              },
                              "path": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              },
                              "message": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "499": {
            "description": "Request aborted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "object",
                      "properties": {
                        "code": {
                          "type": "string",
                          "enum": [
                            "REQUEST_ABORTED"
                          ]
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "get": {
        "deprecated": true,
        "summary": "Service health check (DEPRECATED)",
        "description": "**DEPRECATED:** Use `/api/v1/projects/{projectId}/requirements/{requirementId}/review/acceptance` instead.\n\nReturns basic information about the review service.\n",
        "tags": [
          "Review"
        ],
        "responses": {
          "200": {
            "description": "Service information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "endpoint": {
                      "type": "string"
                    },
                    "methods": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "description": {
                      "type": "string"
                    },
                    "requirements": {
                      "type": "string"
                    },
                    "inputs": {
                      "type": "object",
                      "properties": {
                        "pullRequestUrl": {
                          "type": "string"
                        },
                        "requirementId": {
                          "type": "string"
                        },
                        "externalDocumentUrl": {
                          "type": "string"
                        },
                        "diff": {
                          "type": "string"
                        }
                      }
                    },
                    "streaming": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "service": "BrainGrid Code Review",
                  "version": "v1",
                  "endpoint": "/api/v1/review/acceptance",
                  "methods": [
                    "GET",
                    "POST"
                  ],
                  "description": "AI-powered code review service for pull requests",
                  "requirements": "At least one of pullRequestUrl or requirementId must be provided",
                  "inputs": {
                    "pullRequestUrl": "GitHub pull request URL (required if requirementId not provided)",
                    "requirementId": "BrainGrid requirement ID (required if pullRequestUrl not provided)",
                    "externalDocumentUrl": "External document URL (optional)",
                    "diff": "Direct code diff (optional)"
                  },
                  "streaming": true
                }
              }
            }
          }
        }
      }
    },
    "/v1/supabase-token": {
      "post": {
        "summary": "Mint a short-lived Supabase JWT for Realtime subscriptions",
        "description": "Signs an HS256 JWT using SUPABASE_JWT_SECRET with `role=authenticated`\nand `org_id` bound to the caller's active organization. Used by the\nbrowser Supabase client to authenticate Realtime `postgres_changes`\nsubscriptions so RLS policies can scope access to `auth.jwt() ->>\n'org_id'`.\n\nThe token is sent via Authorization header and lives 90 minutes; the\nbrowser hook schedules a refresh at 80% of TTL (~72 min).\n",
        "tags": [
          "Auth"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Token minted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accessToken": {
                      "type": "string"
                    },
                    "expiresAt": {
                      "type": "integer",
                      "description": "Unix seconds"
                    },
                    "orgId": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "500": {
            "description": "SUPABASE_JWT_SECRET not configured"
          }
        }
      }
    },
    "/v1/webhooks/wf/{slug}": {
      "post": {
        "summary": "Workflow webhook ingress",
        "description": "Public, stable trigger URL for a published workflow. The unguessable\nslug routes the delivery; senders may additionally sign the raw body\nwith HMAC-SHA256 via the `X-BrainGrid-Signature` header (hex digest,\noptionally prefixed `sha256=`). A trigger that has a secret REQUIRES the\nsignature and refuses unsigned deliveries. The JSON body becomes\n`{{ trigger.body }}` inside the run.\n",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "slug",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Run queued — returns the run id"
          },
          "400": {
            "description": "Invalid JSON",
            "signature mismatch": null,
            "or workflow not live": null
          },
          "404": {
            "description": "Unknown webhook"
          },
          "413": {
            "description": "Payload too large"
          }
        }
      }
    },
    "/v1/workspaces": {
      "get": {
        "summary": "List workspaces across all projects in the organization",
        "description": "Returns workspaces for the authenticated user's organization.\nBy default returns ACTIVE, PUBLISHING, and PUBLISH_FAILED workspaces\nplus PUBLISHED workspaces from the last 24 hours. Use the `statuses`\nquery parameter to filter by specific statuses (bypasses default behavior).\n",
        "tags": [
          "Workspaces"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "statuses",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated workspace statuses to filter by (e.g. ACTIVE,PUBLISHING)",
            "example": "ACTIVE,PUBLISHING,PUBLISH_FAILED"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspaces retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "workspaces": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Workspace"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid statuses parameter"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          }
        }
      }
    }
  }
}