{
  "openapi": "3.1.0",
  "info": {
    "title": "Governance Caretaker",
    "version": "1.0.0",
    "description": "Public HTTPS adapter exposing stable Governance Caretaker routes for ChatGPT Actions. Requests are mapped to the upstream Project-AI / Triumvirate governance service. This adapter is not the enforcement kernel; it is a thin governed gateway."
  },
  "servers": [
    {
      "url": "https://www.thirstysystems.com/governance"
    }
  ],
  "components": {
    "securitySchemes": {
      "GovernanceActionKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Governance-Action-Key"
      }
    },
    "schemas": {
      "Constitution": {
        "type": "object",
        "properties": {
          "source": {
            "type": "string"
          },
          "retrieved_at": {
            "type": "string"
          },
          "laws": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "upstream_status": {
            "type": "integer"
          }
        }
      },
      "EnforceRequest": {
        "type": "object",
        "required": [
          "action"
        ],
        "properties": {
          "action": {
            "type": "string",
            "description": "The action or operation to be governed."
          },
          "actor": {
            "type": "string",
            "description": "Identity requesting the action."
          },
          "context": {
            "type": "object",
            "additionalProperties": true,
            "description": "Arbitrary context for the governance decision."
          },
          "risk": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high",
              "critical"
            ],
            "description": "Caller-asserted risk hint."
          }
        }
      },
      "Decision": {
        "type": "object",
        "properties": {
          "decision": {
            "type": "string",
            "enum": [
              "ALLOW",
              "DENY",
              "SAFE_HALT"
            ]
          },
          "reason": {
            "type": "string"
          },
          "upstream_status": {
            "type": "integer"
          },
          "raw": {
            "type": "object"
          }
        }
      },
      "AuditLogRequest": {
        "type": "object",
        "required": [
          "event"
        ],
        "properties": {
          "event": {
            "type": "string",
            "description": "Event type or name."
          },
          "detail": {
            "type": "object",
            "additionalProperties": true
          },
          "actor": {
            "type": "string"
          }
        }
      },
      "ReflexRequest": {
        "type": "object",
        "required": [
          "trigger"
        ],
        "properties": {
          "trigger": {
            "type": "string",
            "description": "Reflex / security trigger name."
          },
          "severity": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high",
              "critical"
            ]
          },
          "detail": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "ProposePatchRequest": {
        "type": "object",
        "required": [
          "summary"
        ],
        "properties": {
          "summary": {
            "type": "string",
            "description": "What the patch changes."
          },
          "target": {
            "type": "string",
            "description": "Component or file targeted."
          },
          "diff": {
            "type": "string",
            "description": "Proposed change body or diff."
          },
          "rationale": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/constitution/current": {
      "get": {
        "operationId": "getCurrentConstitution",
        "summary": "Get the current governance constitution.",
        "description": "Returns a caretaker-friendly constitution object sourced from the upstream four-laws endpoint.",
        "responses": {
          "200": {
            "description": "Current constitution.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Constitution"
                }
              }
            }
          }
        }
      }
    },
    "/enforce": {
      "post": {
        "operationId": "enforceGovernance",
        "summary": "Submit an action for a governance decision.",
        "description": "Converts the request into the upstream Triumvirate intent format and returns the governance decision.",
        "security": [
          {
            "GovernanceActionKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EnforceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Governance decision.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid action key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/audit/log": {
      "post": {
        "operationId": "logAuditEvent",
        "summary": "Record a governance audit event.",
        "description": "Accepts an event and returns an adapter acknowledgement. Does not claim an upstream write unless the upstream supports append-audit.",
        "security": [
          {
            "GovernanceActionKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditLogRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Adapter acknowledgement.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid action key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/audit/trail": {
      "get": {
        "operationId": "getAuditTrail",
        "summary": "Get the normalized governance audit trail.",
        "description": "Fetches and normalizes the upstream audit trail.",
        "responses": {
          "200": {
            "description": "Audit trail.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/reflex/trigger": {
      "post": {
        "operationId": "triggerReflex",
        "summary": "Trigger a reflex / security governance intent.",
        "description": "Converts a reflex/security trigger into an upstream high-risk governance intent.",
        "security": [
          {
            "GovernanceActionKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReflexRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Governance decision for the reflex intent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid action key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/caretaker/status": {
      "get": {
        "operationId": "getCaretakerStatus",
        "summary": "Get adapter and upstream health.",
        "description": "Returns public adapter status plus upstream health from the upstream health endpoint.",
        "responses": {
          "200": {
            "description": "Adapter + upstream status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/caretaker/propose-patch": {
      "post": {
        "operationId": "proposeCaretakerPatch",
        "summary": "Propose a governance patch for review.",
        "description": "Converts a patch proposal into an upstream governance intent for review. Never applies changes directly.",
        "security": [
          {
            "GovernanceActionKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProposePatchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Governance decision for the proposed patch.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Decision"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid action key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}