{
  "openapi": "3.1.0",
  "info": {
    "title": "Achieve Aims Agent API",
    "version": "1.3.0",
    "description": "Guide users conversationally and organize explicitly assigned goals. Create credentials in the signed-in Agent connections screen. Access includes selected unencrypted goals and optional read-only idea sharing. Existing credentials do not gain idea access automatically. The app does not host agent execution."
  },
  "servers": [
    {
      "url": "https://www.achieveaims.com"
    }
  ],
  "security": [
    {
      "agentKey": []
    }
  ],
  "paths": {
    "/api/v1/connection": {
      "get": {
        "operationId": "readConnection",
        "summary": "Read current connection metadata and explicit capabilities",
        "responses": {
          "200": {
            "description": "No token or account data. goalIds are the assigned scope; current ownership and encryption are checked on reads.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connection": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "goalIds": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "canWrite": {
                          "type": "boolean"
                        },
                        "canReadIdeas": {
                          "type": "boolean"
                        },
                        "canProposeGoals": {
                          "type": "boolean"
                        },
                        "expiresAt": {
                          "type": "string"
                        },
                        "createdAt": {
                          "type": "string"
                        },
                        "revokedAt": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "prefix": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/goal-proposals": {
      "post": {
        "operationId": "proposeGoalChanges",
        "summary": "Submit an immutable goal batch for owner review",
        "description": "Requires separate canProposeGoals, not canWrite. 1–20 create/update operations; update requires goal.revision from a fresh workspace read. Supported fields: title, specification (description/details or null), status active/completed/deferred, integer order. Each existing goal appears once. Nothing changes on submission. Return reviewUrl to the owner; only the signed-in owner can apply all changes in the app. Proposal expires in 24 hours; goal limits apply on approval. New goals remain unshared unless the owner explicitly shares them at review. Retry the identical operationId and payload after a lost response. No approval tool is provided to agents.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GoalProposalInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idempotent replay.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoalProposalResult"
                }
              }
            }
          },
          "201": {
            "description": "Pending proposal and owner review link.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoalProposalResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/goal-proposals/{proposalId}": {
      "get": {
        "operationId": "readGoalProposal",
        "summary": "Read this connection’s proposal and decision",
        "parameters": [
          {
            "name": "proposalId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{24}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Poll after owner review. A pending proposal is not a saved goal change.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "proposal": {
                      "$ref": "#/components/schemas/GoalProposal"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/goals": {
      "get": {
        "operationId": "listGoals",
        "summary": "List assigned goals and available capabilities",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{24}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Up to 50 goals; follow nextCursor until null. capabilities.readIdeas indicates whether this connection can read ideas.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "goals": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "status": {
                            "type": "string"
                          },
                          "order": {
                            "type": "number"
                          }
                        }
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "capabilities": {
                      "type": "object",
                      "properties": {
                        "readIdeas": {
                          "type": "boolean"
                        },
                        "proposeGoals": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/ideas": {
      "get": {
        "operationId": "listIdeas",
        "summary": "Read shared ideas; requires separate idea permission",
        "description": "Read-only, including future ideas within scope: unlinked ideas and ideas attached to selected, currently owned, unencrypted goals. Excludes other owners, unassigned/encrypted/deleted goals, private scratchpads, and encrypted ideas. No idea mutations are supported. Existing keys need replacement with a new owner-issued connection with idea sharing enabled.",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[a-fA-F0-9]{24}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Up to 50 ideas, ordered by ID; follow nextCursor until null.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ideas": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "tags": {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          },
                          "goalId": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "goalTitle": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "isActionItem": {
                            "type": "boolean"
                          },
                          "status": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "dueDate": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "createdAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          },
                          "updatedAt": {
                            "type": [
                              "string",
                              "null"
                            ]
                          }
                        }
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "scope": {
                      "const": "unlinked_and_selected_goals"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/today": {
      "get": {
        "operationId": "readToday",
        "summary": "Read the next work for up to 50 active assigned goals",
        "responses": {
          "200": {
            "description": "Up to three open items per goal, sorted by current work and priority.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "goals": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "successCriteria": {
                            "type": "string"
                          },
                          "handoff": {
                            "anyOf": [
                              {
                                "type": "object",
                                "properties": {
                                  "summary": {
                                    "type": "string"
                                  },
                                  "nextAction": {
                                    "type": "string"
                                  },
                                  "actor": {
                                    "type": "object",
                                    "properties": {
                                      "type": {
                                        "enum": [
                                          "human",
                                          "agent"
                                        ]
                                      },
                                      "id": {
                                        "type": "string"
                                      },
                                      "name": {
                                        "type": "string"
                                      }
                                    }
                                  },
                                  "updatedAt": {
                                    "type": "string"
                                  }
                                }
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "format": "uuid"
                                },
                                "title": {
                                  "type": "string"
                                },
                                "description": {
                                  "type": "string"
                                },
                                "successCriteria": {
                                  "type": "string"
                                },
                                "priority": {
                                  "enum": [
                                    "low",
                                    "normal",
                                    "high"
                                  ]
                                },
                                "status": {
                                  "enum": [
                                    "planned",
                                    "in_progress",
                                    "blocked",
                                    "done",
                                    "cancelled"
                                  ]
                                },
                                "blocker": {
                                  "type": "string"
                                },
                                "dependsOn": {
                                  "type": "array",
                                  "items": {
                                    "type": "string"
                                  }
                                },
                                "notes": {
                                  "type": "array",
                                  "items": {
                                    "type": "object",
                                    "properties": {
                                      "id": {
                                        "type": "string"
                                      },
                                      "kind": {
                                        "enum": [
                                          "note",
                                          "evidence"
                                        ]
                                      },
                                      "text": {
                                        "type": "string"
                                      },
                                      "actor": {
                                        "type": "object",
                                        "properties": {
                                          "type": {
                                            "enum": [
                                              "human",
                                              "agent"
                                            ]
                                          },
                                          "id": {
                                            "type": "string"
                                          },
                                          "name": {
                                            "type": "string"
                                          }
                                        }
                                      },
                                      "createdAt": {
                                        "type": "string"
                                      }
                                    }
                                  }
                                },
                                "createdBy": {
                                  "type": "object",
                                  "properties": {
                                    "type": {
                                      "enum": [
                                        "human",
                                        "agent"
                                      ]
                                    },
                                    "id": {
                                      "type": "string"
                                    },
                                    "name": {
                                      "type": "string"
                                    }
                                  }
                                },
                                "updatedBy": {
                                  "type": "object",
                                  "properties": {
                                    "type": {
                                      "enum": [
                                        "human",
                                        "agent"
                                      ]
                                    },
                                    "id": {
                                      "type": "string"
                                    },
                                    "name": {
                                      "type": "string"
                                    }
                                  }
                                },
                                "createdAt": {
                                  "type": "string"
                                },
                                "updatedAt": {
                                  "type": "string"
                                }
                              }
                            }
                          },
                          "openCount": {
                            "type": "integer"
                          },
                          "completedCount": {
                            "type": "integer"
                          },
                          "checklistRemaining": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/goals/{goalId}/workspace": {
      "parameters": [
        {
          "name": "goalId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^[a-fA-F0-9]{24}$"
          }
        }
      ],
      "get": {
        "operationId": "readGoalWorkspace",
        "summary": "Read goal context, current work, and latest handoff",
        "responses": {
          "200": {
            "description": "Resume from this workspace before writing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "goal": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "title": {
                          "type": "string"
                        },
                        "revision": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "order": {
                          "type": "number"
                        },
                        "specification": {},
                        "status": {
                          "type": "string"
                        },
                        "actionItems": {
                          "type": "array",
                          "items": {}
                        },
                        "affirmations": {
                          "type": "array",
                          "items": {}
                        },
                        "progress": {}
                      }
                    },
                    "workspace": {
                      "$ref": "#/components/schemas/Workspace"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateGoalWorkspace",
        "summary": "Update shared work; requires write permission",
        "description": "Reuse the identical command and operationId after a lost response. For version_conflict, read and reconcile before using a new ID. Evidence and completed dependencies are required before reporting an item done. This does not complete the parent goal.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Command"
              },
              "example": {
                "version": 0,
                "operationId": "5c54ec6a-4ea5-4ddb-93bc-082cb45c40dc",
                "operation": {
                  "type": "handoff",
                  "summary": "Reviewed the goal.",
                  "nextAction": "Define the first work item."
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated workspace, or a safe replay of an already-applied command.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "workspace": {
                      "$ref": "#/components/schemas/Workspace"
                    },
                    "replayed": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON, command, ID, or cursor",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Credential invalid, expired, or revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Operation not permitted; ideas_not_shared means idea reading was not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Goal unavailable or outside the credential scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Version, idempotency, or capacity conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Body exceeds 32 KB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Use application/json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Invalid work transition, dependency, or size limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "120 requests per key per minute exceeded; retry next minute",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "agentKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "An aag_ credential created by the owner. Never place it in a URL."
      }
    },
    "schemas": {
      "GoalProposalInput": {
        "type": "object",
        "properties": {
          "operationId": {
            "type": "string",
            "format": "uuid"
          },
          "summary": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000
          },
          "operations": {
            "type": "array",
            "items": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "const": "create"
                    },
                    "goal": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 500
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "active",
                            "completed",
                            "deferred"
                          ],
                          "default": "active"
                        },
                        "order": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 1000000,
                          "default": 0
                        },
                        "specification": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "description": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 4000
                                },
                                "details": {
                                  "type": "array",
                                  "items": {
                                    "type": "string",
                                    "minLength": 1,
                                    "maxLength": 1000
                                  },
                                  "maxItems": 20
                                }
                              },
                              "required": [
                                "description",
                                "details"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ],
                          "default": null
                        }
                      },
                      "required": [
                        "title"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "type",
                    "goal"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string",
                      "const": "update"
                    },
                    "goalId": {
                      "type": "string",
                      "pattern": "^[a-f\\d]{24}$",
                      "description": "Goal ID from list"
                    },
                    "revision": {
                      "type": "string",
                      "pattern": "^[a-f\\d]{64}$"
                    },
                    "changes": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 500
                        },
                        "status": {
                          "type": "string",
                          "enum": [
                            "active",
                            "completed",
                            "deferred"
                          ]
                        },
                        "order": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 1000000
                        },
                        "specification": {
                          "anyOf": [
                            {
                              "type": "object",
                              "properties": {
                                "description": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 4000
                                },
                                "details": {
                                  "type": "array",
                                  "items": {
                                    "type": "string",
                                    "minLength": 1,
                                    "maxLength": 1000
                                  },
                                  "maxItems": 20
                                }
                              },
                              "required": [
                                "description",
                                "details"
                              ],
                              "additionalProperties": false
                            },
                            {
                              "type": "null"
                            }
                          ]
                        }
                      },
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "type",
                    "goalId",
                    "revision",
                    "changes"
                  ],
                  "additionalProperties": false
                }
              ]
            },
            "minItems": 1,
            "maxItems": 20
          }
        },
        "required": [
          "operationId",
          "summary",
          "operations"
        ],
        "additionalProperties": false
      },
      "GoalProposal": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "agentName": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "status": {
            "enum": [
              "pending",
              "applied",
              "rejected"
            ]
          },
          "changes": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "enum": [
                    "create",
                    "update"
                  ]
                },
                "goalId": {
                  "type": "string"
                },
                "before": {},
                "after": {},
                "revision": {
                  "type": "string"
                }
              }
            }
          },
          "reviewHash": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "expiresAt": {
            "type": "string"
          },
          "decidedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "sharedCreatedGoals": {
            "type": "boolean"
          }
        }
      },
      "GoalProposalResult": {
        "type": "object",
        "properties": {
          "proposal": {
            "$ref": "#/components/schemas/GoalProposal"
          },
          "reviewUrl": {
            "type": "string"
          },
          "replayed": {
            "type": "boolean"
          }
        }
      },
      "Command": {
        "type": "object",
        "properties": {
          "operationId": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "operation": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "create_item"
                  },
                  "item": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      },
                      "description": {
                        "type": "string",
                        "maxLength": 4000,
                        "default": ""
                      },
                      "successCriteria": {
                        "type": "string",
                        "maxLength": 2000,
                        "default": ""
                      },
                      "priority": {
                        "type": "string",
                        "enum": [
                          "low",
                          "normal",
                          "high"
                        ],
                        "default": "normal"
                      },
                      "dependsOn": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "maxItems": 20,
                        "default": []
                      }
                    },
                    "required": [
                      "id",
                      "title"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type",
                  "item"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "update_item"
                  },
                  "itemId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "changes": {
                    "type": "object",
                    "properties": {
                      "title": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      },
                      "description": {
                        "type": "string",
                        "maxLength": 4000
                      },
                      "successCriteria": {
                        "type": "string",
                        "maxLength": 2000
                      },
                      "status": {
                        "type": "string",
                        "enum": [
                          "planned",
                          "in_progress",
                          "blocked",
                          "done",
                          "cancelled"
                        ]
                      },
                      "priority": {
                        "type": "string",
                        "enum": [
                          "low",
                          "normal",
                          "high"
                        ]
                      },
                      "blocker": {
                        "type": "string",
                        "maxLength": 2000
                      },
                      "dependsOn": {
                        "type": "array",
                        "items": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "maxItems": 20
                      }
                    },
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type",
                  "itemId",
                  "changes"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "add_note"
                  },
                  "itemId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "kind": {
                    "type": "string",
                    "enum": [
                      "note",
                      "evidence"
                    ]
                  },
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  }
                },
                "required": [
                  "type",
                  "itemId",
                  "kind",
                  "text"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "handoff"
                  },
                  "summary": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  },
                  "nextAction": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                },
                "required": [
                  "type",
                  "summary",
                  "nextAction"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "set_criteria"
                  },
                  "successCriteria": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 4000
                  }
                },
                "required": [
                  "type",
                  "successCriteria"
                ],
                "additionalProperties": false
              }
            ]
          }
        },
        "required": [
          "operationId",
          "version",
          "operation"
        ],
        "additionalProperties": false
      },
      "Workspace": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "minimum": 0
          },
          "successCriteria": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "title": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "successCriteria": {
                  "type": "string"
                },
                "priority": {
                  "enum": [
                    "low",
                    "normal",
                    "high"
                  ]
                },
                "status": {
                  "enum": [
                    "planned",
                    "in_progress",
                    "blocked",
                    "done",
                    "cancelled"
                  ]
                },
                "blocker": {
                  "type": "string"
                },
                "dependsOn": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "notes": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "kind": {
                        "enum": [
                          "note",
                          "evidence"
                        ]
                      },
                      "text": {
                        "type": "string"
                      },
                      "actor": {
                        "type": "object",
                        "properties": {
                          "type": {
                            "enum": [
                              "human",
                              "agent"
                            ]
                          },
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      },
                      "createdAt": {
                        "type": "string"
                      }
                    }
                  }
                },
                "createdBy": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "enum": [
                        "human",
                        "agent"
                      ]
                    },
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                },
                "updatedBy": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "enum": [
                        "human",
                        "agent"
                      ]
                    },
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                },
                "createdAt": {
                  "type": "string"
                },
                "updatedAt": {
                  "type": "string"
                }
              }
            }
          },
          "handoff": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "summary": {
                    "type": "string"
                  },
                  "nextAction": {
                    "type": "string"
                  },
                  "actor": {
                    "type": "object",
                    "properties": {
                      "type": {
                        "enum": [
                          "human",
                          "agent"
                        ]
                      },
                      "id": {
                        "type": "string"
                      },
                      "name": {
                        "type": "string"
                      }
                    }
                  },
                  "updatedAt": {
                    "type": "string"
                  }
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "events": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                },
                "itemId": {
                  "type": "string"
                },
                "actor": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "enum": [
                        "human",
                        "agent"
                      ]
                    },
                    "id": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    }
                  }
                },
                "createdAt": {
                  "type": "string"
                }
              }
            }
          },
          "updatedAt": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
