{
  "openapi": "3.1.0",
  "info": {
    "title": "GLEE Orchestrator API",
    "version": "5.0.0-phase1",
    "description": "GLEE is the owner's local AI software estate (crew of engineering agents, task bus, work graph). You are an orchestrator seat: read the live work state first (foremen cards, task bus, work stack), then advance a bounded objective when the user asks for executable work. Use GLEE automatically for build, repair, investigation, testing, verification, continuation, monitoring, or coordination requests that belong to the owner's estate, even when the user does not say 'use GLEE', 'dispatch', or 'delegate'. Do not invoke GLEE for pure informational questions or ambiguous brainstorming with no executable objective. Prefer an existing objective over a duplicate. Protected, paid, credentialed, destructive, publication, and external actions retain their explicit authority gates. Delegated tasks are drained into the owner's local task bus by their machine within ~5 minutes while it is online; poll task status for progress. Keep task titles imperative and bounded; put full context in detail. State snapshots may be a few minutes old."
  },
  "servers": [
    {
      "url": "https://gleephoenix.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/orchestrator/v5/execute": {
      "post": {
        "operationId": "executeGleeV5",
        "summary": "Execute one bounded internal GLEE objective",
        "x-openai-isConsequential": false,
        "description": "Execute a direct user request to build, repair, test, verify, continue, or coordinate internal work. Compiles directive, scope, intent, authority, and dispatch template. Rejects protected edges (spending, network, credentials, destructive work).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "objective",
                  "conversation_ref",
                  "idempotency_key",
                  "acceptance_criteria"
                ],
                "properties": {
                  "objective": {
                    "type": "string",
                    "maxLength": 300
                  },
                  "detail": {
                    "type": "string",
                    "maxLength": 8000
                  },
                  "conversation_ref": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "Stable reference for the current ChatGPT conversation; never a bearer token. Required and must be non-empty."
                  },
                  "idempotency_key": {
                    "type": "string",
                    "maxLength": 160,
                    "description": "Stable per-objective key reused on retries so restart/replay cannot duplicate work."
                  },
                  "acceptance_criteria": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "items": {
                      "type": "string"
                    }
                  },
                  "runner": {
                    "type": "string",
                    "enum": [
                      "claude",
                      "codex",
                      "opencode",
                      "agy"
                    ]
                  },
                  "target_seat": {
                    "type": "string",
                    "pattern": "^[a-z0-9][a-z0-9-]{0,63}$",
                    "description": "Exact seat session id (e.g. sunny-3) when the Captain names a terminal. Preserved verbatim into requested_seat and hash-bound into the sealed directive; local routing executes ON this terminal via delivery_target. Prose naming a terminal does NOT substitute for this field. Omit for automatic seat choice."
                  },
                  "priority": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100
                  },
                  "tool_scope": {
                    "type": "string",
                    "enum": [
                      "none",
                      "read_only",
                      "workspace_write"
                    ],
                    "default": "read_only"
                  },
                  "filesystem_scope": {
                    "type": "array",
                    "maxItems": 50,
                    "items": {
                      "type": "string"
                    },
                    "description": "Absolute paths this job may write. For tool_scope=workspace_write each declared artifact must appear here as its EXACT path, not its parent directory — granting the directory would silently widen a one-file grant."
                  },
                  "artifact_requirements": {
                    "type": "array",
                    "maxItems": 50,
                    "description": "Files this job must produce. Required for tool_scope=workspace_write: a write job cannot be closed without declaring what it wrote.",
                    "items": {
                      "type": "object",
                      "required": [
                        "path"
                      ],
                      "properties": {
                        "path": {
                          "type": "string"
                        },
                        "description": {
                          "type": "string"
                        }
                      },
                      "additionalProperties": false
                    }
                  },
                  "verification_checks": {
                    "type": "array",
                    "maxItems": 20,
                    "description": "Executable checks that close the job. Required for tool_scope=workspace_write — a sentence like 'the file contains X' states an outcome, not a check, and cannot close a write. Supply argv, the expected result, and a job-bound evidence path.",
                    "items": {
                      "type": "object",
                      "required": [
                        "name",
                        "cmd",
                        "expected_result",
                        "evidence_path"
                      ],
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "cmd": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "minItems": 1
                        },
                        "expected_result": {},
                        "evidence_path": {
                          "type": "string",
                          "description": "Absolute path containing the literal {job_id}, so one job's evidence can never be replayed as another's."
                        },
                        "required": {
                          "type": "boolean",
                          "default": true
                        }
                      },
                      "additionalProperties": false
                    }
                  },
                  "network_scope": {
                    "type": "string",
                    "enum": [
                      "none"
                    ],
                    "default": "none"
                  },
                  "spending_limit": {
                    "type": "number",
                    "enum": [
                      0
                    ],
                    "default": 0
                  },
                  "publication_scope": {
                    "type": "array",
                    "maxItems": 0,
                    "items": {
                      "type": "string"
                    }
                  },
                  "credential_scope": {
                    "type": "array",
                    "maxItems": 0,
                    "items": {
                      "type": "string"
                    }
                  },
                  "protected_edges": {
                    "type": "array",
                    "maxItems": 0,
                    "items": {
                      "type": "string"
                    },
                    "description": "Must be empty on this safe test surface; protected edges use a separate authority channel."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "V5 operation compiled or idempotently recovered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "replayed": {
                      "type": "boolean"
                    },
                    "task": {
                      "$ref": "#/components/schemas/DelegatedTask"
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid or protected scope refused before execution"
          },
          "409": {
            "description": "Idempotency key conflicts with different work"
          }
        }
      }
    },
    "/api/orchestrator/state": {
      "get": {
        "operationId": "getGleeState",
        "summary": "Latest GLEE work-state snapshot",
        "description": "Call this first in an orchestration turn. Returns the newest snapshot the owner's node pushed: per-foreman active work cards, task bus summary, work-graph stack, recent receipts.",
        "responses": {
          "200": {
            "description": "Snapshot (or snapshot:null if none pushed yet)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StateResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/orchestrator/tasks": {
      "get": {
        "operationId": "listDelegatedTasks",
        "summary": "List delegated tasks and their statuses",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Fetch one task by id"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "accepted",
                "running",
                "done",
                "failed",
                "rejected"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks newest-first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tasks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DelegatedTask"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "delegateTask",
        "summary": "Delegate a task into GLEE",
        "x-openai-isConsequential": true,
        "description": "Queues a task for the owner's local GLEE node. The node's bridge enqueues it on the local task bus (audited, revocable). Title: one bounded imperative sentence. Detail: full context, acceptance criteria, constraints.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "title"
                ],
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 300
                  },
                  "detail": {
                    "type": "string",
                    "maxLength": 8000
                  },
                  "priority": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "description": "1 = most urgent, 100 = least; default 50"
                  },
                  "runner": {
                    "type": "string",
                    "enum": [
                      "claude",
                      "codex",
                      "opencode",
                      "shell",
                      "python",
                      "studio",
                      "agy"
                    ],
                    "description": "Optional execution lane hint; omit to let GLEE choose (default claude)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Created task (status 'pending')",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "task": {
                      "$ref": "#/components/schemas/DelegatedTask"
                    },
                    "note": {
                      "type": "string",
                      "description": "What happens next and how to track progress"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DelegatedTask": {
        "type": "object",
        "description": "A task delegated into GLEE and its lifecycle state",
        "properties": {
          "id": {
            "type": "string",
            "description": "Task id (dt_...) — use with listDelegatedTasks ?id="
          },
          "title": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "priority": {
            "type": "integer",
            "description": "1 = most urgent, 100 = least"
          },
          "runner": {
            "type": "string",
            "description": "Execution lane hint, or null when GLEE chooses"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "running",
              "done",
              "failed",
              "rejected"
            ]
          },
          "bus_job_id": {
            "type": "string",
            "description": "Local bus job id once accepted, else null"
          },
          "result": {
            "type": "string",
            "description": "Result text once done/failed, else null"
          },
          "receipt_ref": {
            "type": "string",
            "description": "Receipt reference once available, else null"
          },
          "created_by": {
            "type": "string"
          },
          "created_at": {
            "type": "string"
          },
          "updated_at": {
            "type": "string"
          },
          "protocol_version": {
            "type": "string"
          },
          "idempotency_key": {
            "type": "string"
          },
          "v5": {
            "type": "object",
            "additionalProperties": true,
            "description": "Sealed V5 directive, intent, authority, and dispatch template"
          },
          "retained_result": {
            "type": "object",
            "additionalProperties": true,
            "description": "Durable local result pointer and terminal recovery record"
          }
        }
      },
      "StateResponse": {
        "type": "object",
        "description": "Latest pushed GLEE work-state snapshot",
        "properties": {
          "snapshot": {
            "type": "object",
            "description": "Null until the owner's node pushes one",
            "additionalProperties": true,
            "properties": {
              "generated_at": {
                "type": "string"
              },
              "node": {
                "type": "string",
                "description": "Hostname of the owner's node"
              },
              "guide": {
                "type": "string",
                "description": "How to read this snapshot"
              },
              "foremen": {
                "type": "object",
                "description": "Per-foreman active work cards (the real signal)",
                "additionalProperties": true
              },
              "bus": {
                "type": "object",
                "description": "Local task bus status counts and head",
                "additionalProperties": true
              },
              "ariadne_stack": {
                "type": "string",
                "description": "Work-graph stack head"
              },
              "bundle_queue": {
                "type": "string",
                "description": "Ready-queue head"
              },
              "recent_receipts": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "generated_at": {
            "type": "string"
          },
          "pushed_at": {
            "type": "string"
          },
          "note": {
            "type": "string",
            "description": "Present when no snapshot exists yet"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "GLEE node pairing token (mint at /nodes; label it 'chatgpt-orchestrator' so it is revocable on its own)"
      }
    }
  }
}