{
  "openapi": "3.1.0",
  "info": {
    "title": "ORI Runtime API",
    "version": "2026-04-25",
    "description": "Complete public API surface for integrating ORI. Base URL: https://glm.thynaptic.com/v1"
  },
  "servers": [
    { "url": "https://glm.thynaptic.com/v1", "description": "Shared runtime" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ori.<prefix>.<secret>",
        "description": "Preferred ORI runtime key. Legacy glm.* keys remain valid until rotated."
      },
      "bootstrapAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "agb.<prefix>.<secret>"
      }
    },
    "schemas": {
      "CreateTaskRequest": {
        "type": "object",
        "required": ["title"],
        "properties": {
          "title": { "type": "string" },
          "description": { "type": "string" },
          "surface": { "type": "string", "example": "home", "description": "Originating surface: home, studio, api, etc." },
          "session_id": { "type": "string" },
          "priority": { "type": "integer", "default": 0 },
          "metadata": { "type": "object", "additionalProperties": { "type": "string" } },
          "steps": { "type": "array", "items": { "$ref": "#/components/schemas/CreateStepRequest" } }
        }
      },
      "CreateStepRequest": {
        "type": "object",
        "required": ["title", "action"],
        "properties": {
          "title": { "type": "string" },
          "action": { "type": "string", "enum": ["research","fetch","summarize","compare","draft","generate","save","webhook"] },
          "args": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Action arguments. Common keys: topic, prompt, url, content." },
          "depends_on": { "type": "array", "items": { "type": "string" }, "description": "Step IDs this step depends on. Dependency-free steps run in parallel." },
          "order_num": { "type": "integer" }
        }
      },
      "UpsertEntityRequest": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "id": { "type": "string", "description": "Provide to update an existing entity." },
          "name": { "type": "string", "example": "Mike the Plumber" },
          "kind": { "type": "string", "enum": ["person","business","vendor","account","unknown"] },
          "aliases": { "type": "array", "items": { "type": "string" }, "example": ["the plumber", "plumber mike"] }
        }
      },
      "CreateEntityEventRequest": {
        "type": "object",
        "required": ["kind"],
        "properties": {
          "kind": { "type": "string", "enum": ["message","invoice","booking","call","note","event"] },
          "content": { "type": "string", "example": "Invoice #2024-08 — pipe repair $340" },
          "task_id": { "type": "string", "description": "Link this event to a task." },
          "metadata": { "type": "object", "additionalProperties": { "type": "string" } },
          "occurred_at": { "type": "string", "format": "date-time", "description": "Defaults to now if omitted." }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "scope": { "type": "string" }
        }
      },
      "ChatMessage": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": { "type": "string", "enum": ["system", "user", "assistant"] },
          "content": { "type": "string" }
        }
      },
      "ChatCompletionRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": { "type": "string", "example": "oricli-oracle" },
          "profile": { "type": ["string", "null"], "description": "Optional working style for the chosen surface. Only honored when the profile belongs to the surface set via X-Ori-Context." },
          "stream": { "type": "boolean", "default": false, "description": "Enable SSE streaming." },
          "messages": { "type": "array", "items": { "$ref": "#/components/schemas/ChatMessage" } }
        }
      },
      "ChatCompletionResponse": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "object": { "type": "string" },
          "choices": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "message": { "$ref": "#/components/schemas/ChatMessage" },
                "finish_reason": { "type": "string" }
              }
            }
          },
          "meta": {
            "type": "object",
            "properties": {
              "provider": { "type": "string" },
              "sass_factor": { "type": "number" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Readiness probe",
        "description": "Public. Returns runtime status.",
        "responses": {
          "200": {
            "description": "Ready",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ready" },
                    "system": { "type": "string", "example": "ori-runtime-v2" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ws": {
      "get": {
        "summary": "WebSocket event stream",
        "description": "Public. Real-time state and event streaming. Upgrades to WebSocket.",
        "responses": { "101": { "description": "Switching protocols" } }
      }
    },
    "/metrics": {
      "get": {
        "summary": "Prometheus metrics",
        "description": "Public. Prometheus-compatible metrics for scraping.",
        "responses": { "200": { "description": "Prometheus text format" } }
      }
    },
    "/app/register": {
      "post": {
        "summary": "First-party app self-registration",
        "description": "Protected by a shared internal registration_token, not a runtime key. Mints a product-scoped ORI runtime key (same one-key-anywhere format) for approved first-party apps (ORI Home, ORI Studio, ORI Mobile, ORI Dev). Not a public self-serve developer key flow.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["app_name"],
                "properties": {
                  "app_name": { "type": "string", "example": "ORI Home" },
                  "device_id": { "type": "string", "example": "home-safe-a" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Runtime key minted for the approved app" },
          "401": { "description": "Missing or invalid registration token" }
        }
      }
    },
    "/waitlist": {
      "post": {
        "summary": "Join the waitlist",
        "description": "Public. Marketing → SMB sign-up.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": { "type": "string" },
                  "name": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Joined waitlist" } }
      }
    },
    "/models": {
      "get": {
        "summary": "List available models",
        "description": "Returns the list of public model IDs. Current public default: oricli-oracle.",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": {
            "description": "Model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": { "type": "string" },
                    "data": { "type": "array", "items": { "type": "object" } }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/agent/register": {
      "post": {
        "summary": "Agent-safe bootstrap registration",
        "description": "Accepts an agb.* bootstrap key and mints a product-scoped ORI runtime key (ori.*, one key anywhere) for an approved first-party app. Bootstrap keys can only mint keys for apps they are explicitly authorized for via bootstrap:app:<normalized-app-name> scope. Bootstrap keys do not grant chat, spaces, email, or admin access on their own.",
        "security": [{ "bootstrapAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["app_name"],
                "properties": {
                  "app_name": { "type": "string", "example": "ORI Mobile" },
                  "device_id": { "type": "string", "example": "device-123" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Minted GLM runtime key for the approved app" },
          "401": { "description": "Missing or invalid bootstrap key" },
          "403": { "description": "Bootstrap key lacks required scope for this app" }
        }
      }
    },
    "/mcp": {
      "post": {
        "summary": "Hosted ORI MCP endpoint",
        "description": "Streamable HTTP MCP endpoint at https://glm.thynaptic.com/v1/mcp. Supports initialize, tools/list, and tools/call. Current public runtime tools include get_key_info, check_health, get_capabilities, list_surfaces, list_working_styles, and get_request_template. See /tools.json for the broader published schema catalog.",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "MCP JSON-RPC response" }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "summary": "Chat completion (OpenAI-compatible)",
        "description": "Main ORI chat endpoint. Requires runtime:chat scope. Use X-Ori-Context to select a surface. Use profile for working style. Responses include a meta block with provider and sass_factor.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          {
            "name": "X-Ori-Context",
            "in": "header",
            "required": false,
            "schema": { "type": "string", "enum": ["studio", "home", "dev", "red"] },
            "description": "Product surface selection."
          },
          {
            "name": "X-Session-ID",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Client-generated session ID for conversation history tracking."
          },
          {
            "name": "X-Env-OS",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Dynamic env proprioception: operating system."
          },
          {
            "name": "X-Env-PWD",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Dynamic env proprioception: working directory."
          },
          {
            "name": "X-Env-Project",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Dynamic env proprioception: project name."
          },
          {
            "name": "X-Env-Shell",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Dynamic env proprioception: shell type."
          }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatCompletionRequest" } } }
        },
        "responses": {
          "200": { "description": "Chat completion or SSE stream", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ChatCompletionResponse" } } } },
          "401": { "description": "Missing or invalid API key.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "403": { "description": "Valid key lacks runtime:chat scope.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/chat/feedback": {
      "post": {
        "summary": "Submit vibe/personality feedback",
        "description": "Submit roasts and lessons to improve future ORI personality consistency. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt", "response"],
                "properties": {
                  "prompt": { "type": "string" },
                  "response": { "type": "string" },
                  "sass": { "type": "number", "description": "Desired sass factor 0.0-1.0." },
                  "roast": { "type": "string", "description": "Critique of the response." },
                  "lesson": { "type": "string", "description": "What ORI should learn from this." }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Feedback recorded" } }
      }
    },
    "/email/send": {
      "post": {
        "summary": "Send email via ORI runtime",
        "description": "Send outbound email through ORI's native runtime email layer. Requires runtime:email:send scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["to", "subject", "body"],
                "properties": {
                  "to": { "type": "string", "format": "email" },
                  "subject": { "type": "string" },
                  "body": { "type": "string", "description": "Plain text body." },
                  "html": { "type": "string", "description": "Optional HTML version." }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Email sent" } }
      }
    },
    "/vision/analyze": {
      "post": {
        "summary": "Image analysis",
        "description": "Analyze an image via Oracle (Codex). One of image_url, image_base64, or image_path is required.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "image_url": { "type": "string", "description": "Public image URL." },
                  "image_base64": { "type": "string", "description": "Base64-encoded image data." },
                  "image_path": { "type": "string", "description": "Server-local file path." },
                  "prompt": { "type": "string", "description": "Optional context prompt." },
                  "save_memory": { "type": "boolean", "default": false, "description": "If true and MemoryBank is available, stores as a ProvenanceSeen fragment." }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Analysis result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "description": { "type": "string" },
                    "tags": { "type": "array", "items": { "type": "string" } },
                    "model": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ingest": {
      "post": {
        "summary": "Ingest text into memory",
        "description": "Feed text into ORI's memory and knowledge systems.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object" } } }
        },
        "responses": { "200": { "description": "Ingested" } }
      }
    },
    "/ingest/web": {
      "post": {
        "summary": "Ingest a web URL into memory",
        "description": "Feed a web source into ORI's knowledge/memory systems.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": { "type": "string", "format": "uri" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Web source ingested" } }
      }
    },
    "/goals": {
      "get": {
        "summary": "List goals",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Goal list" } }
      },
      "post": {
        "summary": "Create a goal",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Goal created" } }
      }
    },
    "/goals/{id}": {
      "get": {
        "summary": "Get a goal",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Goal" } }
      },
      "put": {
        "summary": "Update a goal",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Updated" } }
      },
      "delete": {
        "summary": "Delete a goal",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Deleted" } }
      }
    },
    "/memories": {
      "get": {
        "summary": "List memory fragments",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Memory list" } }
      }
    },
    "/memories/knowledge": {
      "get": {
        "summary": "List knowledge memories",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Knowledge memory list" } }
      }
    },
    "/documents/upload": {
      "post": {
        "summary": "Upload a document",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "multipart/form-data": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Document uploaded" } }
      }
    },
    "/documents": {
      "get": {
        "summary": "List documents",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Document list" } }
      }
    },
    "/share": {
      "post": {
        "summary": "Create a share link",
        "description": "Creates a permanent public share link for a canvas artifact.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Share created with public URL" } }
      }
    },
    "/shares": {
      "get": {
        "summary": "List recent shares",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Share list" } }
      }
    },
    "/agents/vibe": {
      "post": {
        "summary": "Natural language agent creation",
        "description": "Create an ORI agent from a natural language description.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Agent definition created" } }
      }
    },
    "/workspaces/run": {
      "post": {
        "summary": "Agentic workspace task execution",
        "description": "Executes an agentic task in an isolated desktop workspace. Requires runtime:workspaces scope. Returns SSE stream.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "SSE task execution stream" } }
      }
    },
    "/capabilities/agent": {
      "post": {
        "summary": "Spawn an autonomous agent",
        "description": "Spawns an autonomous agent task with graduated autonomy and intent-aware routing. The agent classifies query complexity and selects the appropriate model tier, tool permissions, and effort level automatically. Delegation to a background cloud agent is supported — the response will include is_delegated and pr_link when triggered. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Agent task result" } }
      }
    },
    "/capabilities/research": {
      "post": {
        "summary": "Deep research dive",
        "description": "Triggers a deep research dive using read-only tools at high reasoning effort. Produces a comprehensive report with citations. No file mutations or side effects. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["query"],
                "properties": {
                  "query": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Research report" } }
      }
    },
    "/capabilities/web-search": {
      "post": {
        "summary": "Intent-aware web search",
        "description": "Intent-aware SearXNG lookup. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["query"],
                "properties": {
                  "query": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Search results" } }
      }
    },
    "/capabilities/web-fetch": {
      "post": {
        "summary": "RAG-ready URL fetch",
        "description": "Fetches a URL and returns cleaned, RAG-ready context. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": { "type": "string", "format": "uri" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Extracted content" } }
      }
    },
    "/capabilities/repo-report": {
      "post": {
        "summary": "Repository snapshot",
        "description": "High-signal technical repository snapshot. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["repo"],
                "properties": {
                  "repo": { "type": "string", "description": "Repository path or URL." }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Repository report" } }
      }
    },
    "/browser/health": {
      "get": {
        "summary": "Browser runtime health",
        "description": "Check the sovereign browser runtime (browserd) availability.",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Browser health status" } }
      }
    },
    "/browser/sessions": {
      "post": {
        "summary": "Create a browser session",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Session created" } }
      },
      "delete": {
        "summary": "Close a browser session",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Session closed" } }
      }
    },
    "/browser/open": {
      "post": {
        "summary": "Open a URL in the browser session",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": { "type": "string", "format": "uri" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Navigated" } }
      }
    },
    "/browser/snapshot": {
      "get": {
        "summary": "Get browser accessibility snapshot",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Accessibility tree snapshot" } }
      }
    },
    "/browser/action": {
      "post": {
        "summary": "Execute a browser action",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Action result" } }
      }
    },
    "/browser/screenshot": {
      "post": {
        "summary": "Take a browser screenshot",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Screenshot data" } }
      }
    },
    "/browser/state/save": {
      "post": {
        "summary": "Save browser session state",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "State saved" } }
      }
    },
    "/browser/state/load": {
      "post": {
        "summary": "Load browser session state",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "State loaded" } }
      }
    },
    "/tools": {
      "get": {
        "summary": "List available tools",
        "description": "Returns the list of tools available in the current context.",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Tool list" } }
      }
    },
    "/tools/plan": {
      "post": {
        "summary": "Create a tool execution plan",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Tool plan" } }
      }
    },
    "/tools/execute-plan": {
      "post": {
        "summary": "Execute a tool plan",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Execution result" } }
      }
    },
    "/learning/mastery/compile": {
      "post": {
        "summary": "Compile material into mastery artifacts",
        "description": "App-neutral MaterialToMasteryCompiler. Supply extracted user-owned material; ORI returns summary, concept graph, flashcards, drills, quizzes, mock assessments, misconception map, review cadence, mastery score, guided assistance mode, learning DAG, and cross-surface reinforcement hints. Use X-Ori-Context: learn for the reusable learning substrate.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "learn" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "objective": { "type": "string" },
                  "surface": { "type": "string" },
                  "deadline": { "type": "string", "format": "date-time" },
                  "sources": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "kind": { "type": "string", "example": "docs" },
                        "title": { "type": "string" },
                        "content": { "type": "string" }
                      }
                    }
                  },
                  "preferences": { "type": "object" },
                  "existing_ledger": { "type": "object" },
                  "misconceptions": { "type": "array", "items": { "type": "object" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Compiled mastery system" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/quest/scaffold": {
      "post": {
        "summary": "Generate a Quest Scaffold for an improvement goal",
        "description": "App-neutral goal-to-operating-system transformer. Supply a vague improvement goal; ORI returns a named quest, adult role identity, first action, milestones, daily rhythm, workspace sections, progress model, review schedule, memory seeds, and Memory/Chronos/GoalDaemon/PAD integration hints. Product clients still own persistence, reminders, social accountability, and confirmed goal registration.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "home" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "goal": { "type": "string", "example": "I need to study better for my board exam" },
                  "notes": { "type": "string" },
                  "surface": { "type": "string", "example": "home" },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "maxVisibleSteps": { "type": "integer", "example": 4 },
                      "preferredStepMins": { "type": "integer", "example": 20 },
                      "energy": { "type": "string", "example": "medium" },
                      "overwhelmSensitive": { "type": "boolean", "example": true }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Generated quest scaffold" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/behavior/create": {
      "post": {
        "summary": "Create a behavioral reinforcement object",
        "description": "App-neutral Behavioral Reinforcement Substrate. Supply a routine, habit, todo, goal, or shared goal; ORI returns a temporal contract, surface-specific feedback model, initial state, recovery policy, and Memory/Chronos/GoalDaemon/PAD/CALI integration hints. Product clients own durable storage, reminders, widgets, sync, shared rooms, permissions, and reinforcement intensity.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "home" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "type": { "type": "string", "enum": ["daily", "habit", "todo", "goal", "shared_goal"], "example": "daily" },
                  "title": { "type": "string", "example": "Walk for 20 minutes" },
                  "cadence": { "type": "string", "example": "weekday_morning" },
                  "surface": { "type": "string", "example": "home" },
                  "reinforcement_mode": { "type": "string", "example": "calm_progress" },
                  "stakes": { "type": "string", "example": "private" },
                  "recovery_policy": { "type": "string", "example": "adaptive_reschedule" },
                  "privacy": { "type": "string", "example": "private" },
                  "notes": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Behavior object" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/context/momentum": {
      "post": {
        "summary": "Turn messy context into momentum packets",
        "description": "App-neutral Context-to-Momentum Engine. Supply notes, tasks, links, project fragments, user energy, and available time; ORI returns actionability buckets, future-self packets, next 5-minute and 30-minute moves, one preserved stepping stone, memory seeds, and Memory/Chronos/GoalDaemon integration hints. Product clients still own capture, storage, file movement, task creation, reminders, and confirmed archive/write actions.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "current_project": { "type": "string", "example": "homepage rewrite" },
                  "available_minutes": { "type": "integer", "example": 30 },
                  "user_state": {
                    "type": "object",
                    "properties": {
                      "energy": { "type": "string", "example": "low" },
                      "mood": { "type": "string", "example": "scattered" },
                      "mode": { "type": "string", "example": "review" }
                    }
                  },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "max_packets": { "type": "integer", "example": 4 },
                      "overwhelm_sensitive": { "type": "boolean", "example": true },
                      "preserve_novelty": { "type": "boolean", "example": true }
                    }
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string", "example": "Client quote for homepage rewrite" },
                        "content": { "type": "string" },
                        "kind": { "type": "string", "example": "note" },
                        "source": { "type": "string" },
                        "project_hint": { "type": "string" },
                        "status": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Context momentum system" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/procedure/compile": {
      "post": {
        "summary": "Compile observed workflow into an SOP and skill candidate",
        "description": "App-neutral Procedure Compiler. Supply observations, transcript, tools, inputs, outputs, constraints, and outcome signal; ORI returns SOP, checklist, skill candidate, automation readiness, SCL TierSkills seed, and GoalDAG/Chronos/Forge integration hints. Product clients still own durable writes, skill registration, automation execution, permissions, approval gates, and external system changes.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "title": { "type": "string", "example": "support refund triage" },
                  "description": { "type": "string" },
                  "transcript": { "type": "string" },
                  "actor": { "type": "string", "example": "support operator" },
                  "tools": { "type": "array", "items": { "type": "string" } },
                  "inputs": { "type": "array", "items": { "type": "string" } },
                  "outputs": { "type": "array", "items": { "type": "string" } },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "frequency": { "type": "string", "example": "weekly" },
                  "outcome_signal": { "type": "string", "example": "customer receives a correct next step" },
                  "observations": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "title": { "type": "string", "example": "Review customer message" },
                        "detail": { "type": "string" },
                        "actor": { "type": "string" },
                        "tool": { "type": "string", "example": "crm" },
                        "evidence": { "type": "string" },
                        "outcome": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Compiled procedure" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/workflow/grammar/compile": {
      "post": {
        "summary": "Compile natural-language workflow intent into trigger/action grammar",
        "description": "App-neutral Workflow Grammar Compiler. Supply workflow intent, natural-language specification, trigger, conditions, action hints, available tools, approvals, constraints, and exceptions; ORI returns a trigger/action graph, variables, approval gates, failure modes, dry-run plan, readiness score, compiled expression, and Procedure/WorkGraph/Temporal/Forge/Memory integration hints. Product clients still own durable workflow registration, external writes, schedules, notifications, execution, credentials, permissions, and approval UX.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "title": { "type": "string", "example": "quote request follow-up workflow" },
                  "intent": { "type": "string", "example": "turn inbound quote requests into reviewed follow-up drafts" },
                  "specification": { "type": "string", "example": "When a new quote email arrives then review the request then create a CRM task and draft a follow-up unless budget or date is missing." },
                  "trigger": { "type": "string", "example": "new quote email arrives" },
                  "conditions": { "type": "array", "items": { "type": "string" } },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "exceptions": { "type": "array", "items": { "type": "string" } },
                  "outputs": { "type": "array", "items": { "type": "string" } },
                  "actions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "title": { "type": "string", "example": "Draft a follow-up email" },
                        "tool": { "type": "string", "example": "email" },
                        "owner": { "type": "string", "example": "operator" },
                        "when": { "type": "string" },
                        "unless": { "type": "string" },
                        "needs": { "type": "array", "items": { "type": "string" } },
                        "done_signal": { "type": "string" },
                        "destructive": { "type": "boolean" }
                      }
                    }
                  },
                  "available_tools": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": { "type": "string", "example": "email" },
                        "kind": { "type": "string", "example": "inbox" },
                        "actions": { "type": "array", "items": { "type": "string" } },
                        "read_only": { "type": "boolean" },
                        "requires_approval": { "type": "boolean" }
                      }
                    }
                  },
                  "approvals": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "when": { "type": "string", "example": "before sending customer email" },
                        "owner": { "type": "string", "example": "operator" },
                        "reason": { "type": "string" }
                      }
                    }
                  },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "max_nodes": { "type": "integer", "example": 8 },
                      "require_human_approvals": { "type": "boolean", "example": true },
                      "dry_run_first": { "type": "boolean", "example": true },
                      "prefer_read_only": { "type": "boolean", "example": false }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Compiled workflow grammar" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/actions/plan": {
      "post": {
        "summary": "Plan a governed external action route",
        "description": "App-neutral Sovereign Action Gateway planner. Supply intent, action hints, available providers, scopes, approval policy, risk tolerance, and memory policy; ORI returns ranked action candidates, recommended provider route, approval gate, policy labels, audit plan, dry-run instructions, memory plan, and WorkflowGrammar/WorkGraph/CALI/SCL/Chronos/Red integration hints. This endpoint does not execute external actions; product clients still own credentials, real execution, approval UX, durable action logs, notifications, schedules, and external mutations.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "intent": { "type": "string", "example": "send a follow-up email to a new quote lead" },
                  "context": { "type": "string" },
                  "risk_tolerance": { "type": "string", "example": "medium" },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "action_hints": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "title": { "type": "string", "example": "Send quote follow-up email" },
                        "provider": { "type": "string", "example": "native email" },
                        "tool": { "type": "string", "example": "email" },
                        "inputs": { "type": "array", "items": { "type": "string" } },
                        "effects": { "type": "array", "items": { "type": "string" } },
                        "destructive": { "type": "boolean" },
                        "external": { "type": "boolean" }
                      }
                    }
                  },
                  "available_providers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string", "example": "native_email" },
                        "name": { "type": "string", "example": "Native Email" },
                        "kind": { "type": "string", "example": "native" },
                        "capabilities": { "type": "array", "items": { "type": "string" } },
                        "scopes": { "type": "array", "items": { "type": "string" } },
                        "reliability": { "type": "string", "example": "high" },
                        "cost": { "type": "string", "example": "low" },
                        "requires_approval": { "type": "boolean" },
                        "read_only": { "type": "boolean" },
                        "available": { "type": "boolean" }
                      }
                    }
                  },
                  "approval_policy": {
                    "type": "object",
                    "properties": {
                      "require_for_external_writes": { "type": "boolean", "example": true },
                      "require_for_customer_touch": { "type": "boolean", "example": true },
                      "require_for_money": { "type": "boolean", "example": true },
                      "require_for_destructive": { "type": "boolean", "example": true },
                      "allowed_autonomous_effects": { "type": "array", "items": { "type": "string" } },
                      "approval_owner": { "type": "string", "example": "operator" }
                    }
                  },
                  "memory_policy": {
                    "type": "object",
                    "properties": {
                      "minimize_context": { "type": "boolean", "example": true },
                      "allowed_memory_kinds": { "type": "array", "items": { "type": "string" } },
                      "prohibited_memory_kinds": { "type": "array", "items": { "type": "string" } },
                      "record_outcome": { "type": "boolean", "example": true }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Governed action route plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/conversation/harvest": {
      "post": {
        "summary": "Harvest useful context from a conversation",
        "description": "App-neutral Conversational Context Harvester. Supply meeting/chat transcripts, participant turns, intent, and context links; ORI returns decisions, commitments, unresolved threads, follow-up packets, memory seeds, and Memory/Chronos/GoalDAG/Procedure integration hints. Product clients still own note storage, memory writes, task creation, reminders, CRM/calendar updates, and confirmed persistence.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "title": { "type": "string", "example": "client launch sync" },
                  "intent": { "type": "string", "example": "coordinate launch work" },
                  "transcript": { "type": "string" },
                  "participants": { "type": "array", "items": { "type": "string" } },
                  "context_links": { "type": "array", "items": { "type": "string" } },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "speaker": { "type": "string", "example": "Mike" },
                        "text": { "type": "string", "example": "We decided the landing page ships Friday." },
                        "time": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Conversation context harvest" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/temporal/coordinate": {
      "post": {
        "summary": "Coordinate tasks against attention windows",
        "description": "App-neutral Temporal Coordination Engine. Supply tasks, available attention windows, fixed events, energy, dependencies, and preferences; ORI returns now/next/later buckets, schedule proposals, conflicts, memory seeds, and Chronos/GoalDAG/Memory automation hints. Product clients still own calendar writes, task mutations, reminders, notifications, conflict resolution, and confirmed commitment moves.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "horizon": { "type": "string", "example": "today" },
                  "energy": { "type": "string", "example": "low" },
                  "available": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "label": { "type": "string", "example": "morning focus" },
                        "start": { "type": "string" },
                        "end": { "type": "string" },
                        "minutes": { "type": "integer", "example": 45 },
                        "energy": { "type": "string", "example": "medium" }
                      }
                    }
                  },
                  "fixed_events": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "title": { "type": "string" },
                        "start": { "type": "string" },
                        "end": { "type": "string" },
                        "minutes": { "type": "integer" }
                      }
                    }
                  },
                  "tasks": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string", "example": "Send client launch update" },
                        "project": { "type": "string" },
                        "minutes": { "type": "integer", "example": 15 },
                        "due_hint": { "type": "string", "example": "today" },
                        "energy": { "type": "string", "example": "medium" },
                        "importance": { "type": "string", "example": "high" },
                        "status": { "type": "string" },
                        "dependencies": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "max_blocks": { "type": "integer", "example": 5 },
                      "protect_focus": { "type": "boolean", "example": true },
                      "prefer_short_starts": { "type": "boolean", "example": true }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Temporal coordination plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/ambient/continuity/compile": {
      "post": {
        "summary": "Compile supplied context into an ambient continuity ledger",
        "description": "App-neutral Ambient Continuity Ledger compiler. Supply active goal/project, recent events, work items, temporal commitments, and optional previous ledger; ORI returns a compact cross-surface ledger, paused work, open loops, commitments, recent events, cooldown hints, suggestion_context for /ambient/intent/suggest, and AmbientIntent/Continuity/IntentTimeline/WorkGraph/Temporal/Memory hints. Product clients still own capture, storage, durable ledgers, sync, reminders, notifications, consent policy, and all external mutations.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "profile": { "type": "string", "example": "studio_operations" },
                  "active_goal": { "type": "string", "example": "finish launch prep" },
                  "active_project": { "type": "string", "example": "launch deck" },
                  "recent_events": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "kind": { "type": "string", "example": "session" },
                        "title": { "type": "string", "example": "deck editing session" },
                        "project": { "type": "string" },
                        "status": { "type": "string" },
                        "source": { "type": "string" },
                        "time": { "type": "string" },
                        "summary": { "type": "string" },
                        "signals": { "type": "array", "items": { "type": "string" } },
                        "recurrence": { "type": "string" }
                      }
                    }
                  },
                  "work_items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "kind": { "type": "string", "example": "task" },
                        "title": { "type": "string", "example": "launch deck" },
                        "project": { "type": "string" },
                        "surface": { "type": "string" },
                        "status": { "type": "string", "example": "paused" },
                        "owner": { "type": "string" },
                        "due_window": { "type": "string", "example": "today" },
                        "last_action": { "type": "string", "example": "outline finished yesterday" },
                        "next_action": { "type": "string", "example": "continue the deck" },
                        "evidence": { "type": "array", "items": { "type": "string" } },
                        "confidence": { "type": "number", "example": 0.8 }
                      }
                    }
                  },
                  "temporal_commitments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string" },
                        "status": { "type": "string" },
                        "due_window": { "type": "string" },
                        "trigger": { "type": "string" },
                        "source": { "type": "string" },
                        "confidence": { "type": "number" }
                      }
                    }
                  },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "max_paused_work": { "type": "integer", "example": 5 },
                      "max_open_loops": { "type": "integer", "example": 6 },
                      "max_commitments": { "type": "integer", "example": 6 },
                      "max_recent_events": { "type": "integer", "example": 8 },
                      "keep_resolved_context": { "type": "boolean", "example": false }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Ambient continuity ledger" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/ambient/intent/suggest": {
      "post": {
        "summary": "Suggest low-pressure ambient continuations",
        "description": "App-neutral Ambient Intent layer. Supply recent events, continuity context, WorkGraph snippets, temporal commitments, user tempo, and interruption budget; ORI returns ranked micro-suggestions, reasons, confidence, interruption cost, suggested copy, confirmation-gated actions, and Continuity/Intent/WorkGraph/Temporal/Execution/Behavior hints. Product clients still own capture, storage, durable ledgers, reminders, notifications, UI, external execution, and consent policy.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "profile": { "type": "string", "example": "studio_operations" },
                  "suggestion_budget": { "type": "integer", "example": 3 },
                  "user_state": {
                    "type": "object",
                    "properties": {
                      "energy": { "type": "string", "example": "low" },
                      "tempo": { "type": "string", "example": "overloaded" },
                      "interruption_tolerance": { "type": "string", "example": "normal" }
                    }
                  },
                  "recent_events": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "kind": { "type": "string", "example": "game" },
                        "title": { "type": "string", "example": "Hearthstone match" },
                        "project": { "type": "string" },
                        "status": { "type": "string" },
                        "source": { "type": "string" },
                        "time": { "type": "string" },
                        "summary": { "type": "string", "example": "User usually checks logs after matches." },
                        "signals": { "type": "array", "items": { "type": "string" } },
                        "recurrence": { "type": "string", "example": "after matches" }
                      }
                    }
                  },
                  "continuity": {
                    "type": "object",
                    "properties": {
                      "active_goal": { "type": "string" },
                      "active_project": { "type": "string", "example": "launch deck" },
                      "paused_work": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "title": { "type": "string", "example": "launch deck" },
                            "project": { "type": "string" },
                            "surface": { "type": "string" },
                            "paused_at": { "type": "string", "example": "yesterday" },
                            "last_action": { "type": "string", "example": "outline finished" },
                            "next_action": { "type": "string", "example": "continue the deck" },
                            "evidence": { "type": "array", "items": { "type": "string" } },
                            "confidence": { "type": "number", "example": 0.8 }
                          }
                        }
                      },
                      "open_loops": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "title": { "type": "string" },
                            "owner": { "type": "string" },
                            "status": { "type": "string" },
                            "due_window": { "type": "string" },
                            "source": { "type": "string" },
                            "confidence": { "type": "number" }
                          }
                        }
                      }
                    }
                  },
                  "temporal_commitments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string", "example": "restart backbone after smoke" },
                        "status": { "type": "string", "example": "stale" },
                        "due_window": { "type": "string", "example": "yesterday" },
                        "trigger": { "type": "string" },
                        "source": { "type": "string" },
                        "confidence": { "type": "number", "example": 0.75 }
                      }
                    }
                  },
                  "workgraph": {
                    "type": "object",
                    "properties": {
                      "items": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "kind": { "type": "string" },
                            "title": { "type": "string" },
                            "project": { "type": "string" },
                            "status": { "type": "string" },
                            "owner": { "type": "string" },
                            "due_window": { "type": "string" },
                            "signals": { "type": "array", "items": { "type": "string" } },
                            "confidence": { "type": "number" }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Ambient intent suggestion plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/ambient/policy/evaluate": {
      "post": {
        "summary": "Gate ambient suggestions against cooldown and interruption policy",
        "description": "App-neutral Ambient Suggestion Policy gate. Supply Ambient Intent suggestions, cooldown hints, recent policy decisions, user tempo, and policy preferences; ORI returns visible, delayed, and suppressed suggestions with reasons, policy scores, next-review hints, and AmbientIntent/Continuity/Execution/Behavior/Memory integration hints. Product clients still own rendering, notifications, preference storage, durable cooldown state, and all external actions.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "profile": { "type": "string", "example": "studio_operations" },
                  "user_state": {
                    "type": "object",
                    "properties": {
                      "energy": { "type": "string", "example": "low" },
                      "tempo": { "type": "string", "example": "overloaded" },
                      "interruption_tolerance": { "type": "string", "example": "low" }
                    }
                  },
                  "suggestions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string", "example": "amb_resume_launch_deck" },
                        "type": { "type": "string", "example": "resume" },
                        "copy": { "type": "string", "example": "Continue the deck?" },
                        "target": { "type": "string", "example": "deck" },
                        "reason": { "type": "string" },
                        "confidence": { "type": "number", "example": 0.86 },
                        "interruption_cost": { "type": "string", "example": "low" },
                        "tempo": { "type": "string", "example": "neutral" },
                        "surface": { "type": "string", "example": "studio" },
                        "evidence": { "type": "array", "items": { "type": "string" } },
                        "action": {
                          "type": "object",
                          "properties": {
                            "kind": { "type": "string", "example": "continue" },
                            "requires_confirmation": { "type": "boolean", "example": true }
                          }
                        }
                      }
                    }
                  },
                  "cooldown_hints": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "target": { "type": "string", "example": "deck" },
                        "reason": { "type": "string", "example": "Avoid repeating resume prompts too often." },
                        "window": { "type": "string", "example": "session" }
                      }
                    }
                  },
                  "recent_decisions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "suggestion_id": { "type": "string" },
                        "target": { "type": "string" },
                        "decision": { "type": "string", "example": "dismiss" },
                        "reason": { "type": "string" },
                        "at": { "type": "string" },
                        "cooldown_until": { "type": "string" }
                      }
                    }
                  },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "max_visible": { "type": "integer", "example": 1 },
                      "min_confidence": { "type": "number", "example": 0.66 },
                      "respect_dismissals": { "type": "boolean", "example": true },
                      "delay_medium_interrupts": { "type": "boolean", "example": true },
                      "allow_urgent_commitments": { "type": "boolean", "example": false }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Ambient suggestion policy plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/ambient/action/route": {
      "post": {
        "summary": "Route accepted ambient suggestions to confirmation-gated primitive drafts",
        "description": "App-neutral Ambient Accepted Suggestion Handoff. Supply an accepted Ambient Intent suggestion, optional policy decision, continuity ledger, user state, and surface context; ORI returns the recommended downstream primitive, endpoint, request payload draft, confirmation requirement, risk notes, cooldown/memory update hints, and client-owned action boundaries. It does not execute the drafted call, mutate external systems, notify users, or persist state.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "profile": { "type": "string", "example": "studio_operations" },
                  "accepted_at": { "type": "string", "example": "2026-05-19T12:00:00Z" },
                  "suggestion": {
                    "type": "object",
                    "required": ["type", "target"],
                    "properties": {
                      "id": { "type": "string", "example": "amb_resume_launch_deck" },
                      "type": { "type": "string", "example": "resume" },
                      "copy": { "type": "string", "example": "Continue the deck?" },
                      "target": { "type": "string", "example": "launch deck" },
                      "reason": { "type": "string", "example": "The deck was paused yesterday." },
                      "confidence": { "type": "number", "example": 0.86 },
                      "interruption_cost": { "type": "string", "example": "low" },
                      "tempo": { "type": "string", "example": "neutral" },
                      "surface": { "type": "string", "example": "studio" },
                      "evidence": { "type": "array", "items": { "type": "string" } },
                      "action": {
                        "type": "object",
                        "properties": {
                          "kind": { "type": "string", "example": "continue" },
                          "requires_confirmation": { "type": "boolean", "example": true }
                        }
                      }
                    }
                  },
                  "policy": {
                    "type": "object",
                    "properties": {
                      "decision": { "type": "string", "example": "show" },
                      "reason": { "type": "string", "example": "Suggestion clears confidence and interruption policy." },
                      "policy_score": { "type": "number", "example": 0.9 }
                    }
                  },
                  "continuity": {
                    "type": "object",
                    "properties": {
                      "temporal_commitments": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "title": { "type": "string" },
                            "due_window": { "type": "string", "example": "today" }
                          }
                        }
                      },
                      "open_loops": {
                        "type": "array",
                        "items": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "title": { "type": "string" },
                            "due_window": { "type": "string" }
                          }
                        }
                      }
                    }
                  },
                  "user_state": {
                    "type": "object",
                    "properties": {
                      "energy": { "type": "string", "example": "steady" },
                      "tempo": { "type": "string", "example": "normal" },
                      "interruption_tolerance": { "type": "string", "example": "normal" }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Accepted ambient action route plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/anticipation/prepare": {
      "post": {
        "summary": "Prepare bounded context for an upcoming situation",
        "description": "App-neutral Ambient Anticipation layer. Supply upcoming situations, intent, participants, context signals, preferences, and recent outcomes; ORI returns readiness scoring, prep packets, missing context, suggested tone, safe next moves, memory seeds, and Memory/Chronos/Conversation/Temporal integration hints. Product clients still own email, calendar, CRM, memory, notification, task writes, and confirmed durable or external actions.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "situation": { "type": "string", "example": "client renewal call" },
                  "intent": { "type": "string", "example": "advance customer work" },
                  "time_horizon": { "type": "string", "example": "tomorrow" },
                  "participants": { "type": "array", "items": { "type": "string" } },
                  "known_context": { "type": "array", "items": { "type": "string" } },
                  "recent_outcomes": { "type": "array", "items": { "type": "string" } },
                  "signals": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "source": { "type": "string", "example": "crm" },
                        "title": { "type": "string", "example": "Customer asked about pricing" },
                        "content": { "type": "string", "example": "They want the annual plan before renewal." },
                        "urgency": { "type": "string", "example": "medium" },
                        "confidence": { "type": "number", "example": 0.72 },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "preferences": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "subject": { "type": "string", "example": "Dana" },
                        "preference": { "type": "string", "example": "prefers concise options" },
                        "evidence": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Ambient anticipation plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/codebase/task/plan": {
      "post": {
        "summary": "Plan scoped codebase work from repo context",
        "description": "App-neutral Codebase-Resident Task Agent planner. Supply developer intent, repo area, file/symbol signals, constraints, known risks, and test commands; ORI returns scoped work packets, file ownership proposals, risk flags, verification steps, delegation hints, memory seeds, and Procedure/Temporal/Memory/Forge integration hints. Agent runtimes still own actual reads, edits, tests, commits, deployment, permissions, and protection of unrelated user changes.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "dev" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "dev" },
                  "intent": { "type": "string", "example": "add a cognition endpoint" },
                  "repo": { "type": "string", "example": "/home/mike/Mavaia" },
                  "current_area": { "type": "string", "example": "pkg/api" },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "known_risks": { "type": "array", "items": { "type": "string" } },
                  "test_commands": { "type": "array", "items": { "type": "string" } },
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "path": { "type": "string", "example": "pkg/api/server_v2.go" },
                        "role": { "type": "string", "example": "api" },
                        "reason": { "type": "string" },
                        "status": { "type": "string" },
                        "owners": { "type": "array", "items": { "type": "string" } },
                        "can_modify": { "type": "boolean", "example": true }
                      }
                    }
                  },
                  "symbols": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "name": { "type": "string" },
                        "kind": { "type": "string" },
                        "file": { "type": "string" },
                        "role": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Codebase resident task plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/continuity/recover": {
      "post": {
        "summary": "Recover compact project continuity",
        "description": "App-neutral Continuity Recovery Engine. Supply previous sessions, artifacts, decisions, commitments, open loops, intent, and project context; ORI returns a recovered thread, context packets, decision/commitment logs, open-loop state, suggested continuation, memory seeds, and Memory/Chronos/Conversation/Temporal/Procedure hints. Product clients still own durable memory writes, project snapshots, document/task updates, timelines, notifications, and source-of-truth storage.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "dev" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "dev" },
                  "intent": { "type": "string", "example": "resume cognition primitive work" },
                  "current_query": { "type": "string" },
                  "project": { "type": "string", "example": "ORI primitives" },
                  "decisions": { "type": "array", "items": { "type": "string" } },
                  "commitments": { "type": "array", "items": { "type": "string" } },
                  "open_loops": { "type": "array", "items": { "type": "string" } },
                  "previous_sessions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string" },
                        "summary": { "type": "string" },
                        "outcome": { "type": "string" },
                        "updated_at": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "artifacts": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string" },
                        "kind": { "type": "string" },
                        "source": { "type": "string" },
                        "summary": { "type": "string" },
                        "status": { "type": "string" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Continuity recovery plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/execution/orchestrate": {
      "post": {
        "summary": "Choose the next best execution move",
        "description": "App-neutral Intent-First Execution Orchestrator. Supply goal/intent, task state, blockers, dependencies, energy, available time, and recent signals; ORI returns a momentum score, next-best move, next options, blocked-because reasoning, dependency edges, memory seeds, and Continuity/Temporal/Procedure/Memory hints. Product clients still own issue/task mutations, project board writes, scheduling, assignment, notifications, and external execution.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "intent": { "type": "string", "example": "continue launch work" },
                  "goal": { "type": "string" },
                  "energy": { "type": "string", "example": "medium" },
                  "available_minutes": { "type": "integer", "example": 20 },
                  "recent_signals": { "type": "array", "items": { "type": "string" } },
                  "tasks": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string" },
                        "project": { "type": "string" },
                        "status": { "type": "string" },
                        "importance": { "type": "string" },
                        "minutes": { "type": "integer" },
                        "dependencies": { "type": "array", "items": { "type": "string" } },
                        "evidence": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "blockers": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string" },
                        "owner": { "type": "string" },
                        "severity": { "type": "string" }
                      }
                    }
                  },
                  "preferences": {
                    "type": "object",
                    "properties": {
                      "max_next_options": { "type": "integer", "example": 4 },
                      "prefer_small_starts": { "type": "boolean", "example": true },
                      "overwhelm_sensitive": { "type": "boolean", "example": true },
                      "require_visible_proof": { "type": "boolean", "example": true }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Execution orchestration plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/workgraph/compile": {
      "post": {
        "summary": "Compile messy work context into typed WorkGraph state",
        "description": "WorkGraph v0. Supply messy operator context, notes, conversations, and work items; ORI returns typed work-state objects including jobs, tasks, decisions, owners, deadlines, blockers, approvals, notes, follow-ups, and metrics, plus graph edges, operator pulse, memory seeds, and Continuity/Execution/Conversation/Temporal/Procedure hints. Product clients still own durable graph storage, workspace UI, dashboards, permissions, notifications, task/document writes, and external mutations.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "workspace": { "type": "string", "example": "Acme launch" },
                  "intent": { "type": "string", "example": "structure my current work mess" },
                  "notes": { "type": "string" },
                  "conversations": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "speaker": { "type": "string" },
                        "text": { "type": "string" },
                        "time": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "kind": { "type": "string", "example": "job" },
                        "title": { "type": "string", "example": "Acme launch project" },
                        "content": { "type": "string" },
                        "owner": { "type": "string", "example": "Mike" },
                        "due_hint": { "type": "string", "example": "Friday" },
                        "status": { "type": "string", "example": "active" },
                        "source": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Compiled WorkGraph" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/workgraph/answer": {
      "post": {
        "summary": "Answer operator questions over supplied WorkGraph state",
        "description": "Ambient Answers over supplied WorkGraph state. Ask questions like what is stuck, what was promised, what needs approval, who owns this, or what should be handled first; ORI returns findings, recommended moves, confidence, and Execution/Continuity/Memory hints. Answers use supplied graph state only and do not mutate workspaces.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "question": { "type": "string", "example": "What needs approval?" },
                  "graph": { "type": "object" },
                  "objects": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "WorkGraph answer" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/contextual-action/plan": {
      "post": {
        "summary": "Plan governed contextual action for an entity",
        "description": "Contextual Action Fabric. Supply an entity, objective, surface context, available tools, evidence, signals, and constraints; ORI returns an entity profile, evidence acquisition plan, fit/confidence score, governed action recommendations, reusable Skill Function candidate, memory seeds, and WorkGraph/Execution/Procedure/Memory/Temporal hints. Product clients still own provider calls, paid enrichment, CRM updates, outreach, budgets, audit logs, and approvals.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "objective": { "type": "string", "example": "decide best follow-up" },
                  "business_context": { "type": "string" },
                  "available_tools": { "type": "array", "items": { "type": "string" } },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "entity": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "string" },
                      "name": { "type": "string", "example": "Acme Co" },
                      "kind": { "type": "string", "example": "account" },
                      "fields": { "type": "object", "additionalProperties": { "type": "string" } }
                    }
                  },
                  "evidence": { "type": "array", "items": { "type": "object" } },
                  "signals": { "type": "array", "items": { "type": "object" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Contextual action plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/signals/opportunities": {
      "post": {
        "summary": "Detect timely opportunities from entity signals",
        "description": "Signal Opportunity layer. Supply entity-bound signals, context, objective, and optional timing windows; ORI returns ranked opportunities, a handle-first recommendation, watchlist candidates, memory seeds, and Contextual Action/Temporal/WorkGraph hints. Product clients still own durable watches, alerts, notifications, external monitoring, and execution approval.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "objective": { "type": "string", "example": "decide follow-up timing" },
                  "entity": { "type": "object" },
                  "signals": { "type": "array", "items": { "type": "object" } },
                  "context": { "type": "array", "items": { "type": "object" } },
                  "windows": { "type": "array", "items": { "type": "object" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Signal opportunity plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/intent/timeline": {
      "post": {
        "summary": "Preserve intent and rationale across work changes",
        "description": "Intent Timeline. Supply work events, artifacts, decisions, constraints, outcomes, and open loops; ORI returns preserved intent moments, detected intent shifts, rationale trails, current-intent state, continuity packets, memory seeds, and Continuity/WorkGraph/Procedure/Memory/Temporal hints. Product clients still own durable memory, task/document updates, artifact writes, timelines, and source-of-truth storage.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "dev" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "dev" },
                  "project": { "type": "string", "example": "ORI primitives" },
                  "objective": { "type": "string", "example": "preserve rationale across code changes" },
                  "current_goal": { "type": "string" },
                  "decisions": { "type": "array", "items": { "type": "string" } },
                  "open_loops": { "type": "array", "items": { "type": "string" } },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "time": { "type": "string" },
                        "actor": { "type": "string" },
                        "artifact": { "type": "string" },
                        "action": { "type": "string" },
                        "intent": { "type": "string" },
                        "rationale": { "type": "string" },
                        "constraint": { "type": "string" },
                        "outcome": { "type": "string" },
                        "evidence": { "type": "array", "items": { "type": "string" } },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Intent timeline" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/procedural/crystallize": {
      "post": {
        "summary": "Crystallize repeated workflows into procedure and skill candidates",
        "description": "Procedural Crystallizer. Supply repeated workflow runs, triggers, steps, tools, pain points, inputs, outputs, and outcome signals; ORI returns pattern readiness, a candidate procedure, skill candidate, automation readiness, next-observation plan, memory seeds, and Procedure/Skills/WorkGraph/Memory/Temporal/Forge hints. Product clients still own durable writes, skill registration, automation execution, schedules, notifications, approvals, and external mutations.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "studio" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "studio" },
                  "workflow": { "type": "string", "example": "weekly client status prep" },
                  "objective": { "type": "string", "example": "reduce repeated prep work" },
                  "trigger": { "type": "string", "example": "before Friday client updates" },
                  "observed_steps": { "type": "array", "items": { "type": "string" } },
                  "tools": { "type": "array", "items": { "type": "string" } },
                  "inputs": { "type": "array", "items": { "type": "string" } },
                  "outputs": { "type": "array", "items": { "type": "string" } },
                  "pain_points": { "type": "array", "items": { "type": "string" } },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "outcome_signal": { "type": "string" },
                  "runs": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "time": { "type": "string" },
                        "trigger": { "type": "string" },
                        "steps": { "type": "array", "items": { "type": "string" } },
                        "tools": { "type": "array", "items": { "type": "string" } },
                        "outcome": { "type": "string" },
                        "friction": { "type": "string" },
                        "evidence": { "type": "array", "items": { "type": "string" } },
                        "completed": { "type": "boolean" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Procedural crystallization plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/memory/semantic/graph": {
      "post": {
        "summary": "Build an ontology-free semantic memory graph",
        "description": "Semantic Memory Graph. Supply loose captures, notes, existing node hints, tags, people, objects, source handles, and retrieval questions; ORI returns ontology-free nodes, edges, soft clusters, recoverability scoring, retrieval moves, progressive-structure guidance, memory seeds, and Memory/WorkGraph/Continuity/Intent/Procedure hints. Product clients still own durable memory persistence, source storage, permissions, deletion policy, artifact/task updates, and external mutations.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "home" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "home" },
                  "objective": { "type": "string", "example": "recover context without folders" },
                  "workspace": { "type": "string", "example": "family logistics" },
                  "query": { "type": "string", "example": "what school obligations are active?" },
                  "constraints": { "type": "array", "items": { "type": "string" } },
                  "captures": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string" },
                        "content": { "type": "string" },
                        "source": { "type": "string" },
                        "kind": { "type": "string", "example": "document" },
                        "time": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } },
                        "people": { "type": "array", "items": { "type": "string" } },
                        "objects": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "existing_nodes": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "label": { "type": "string" },
                        "kind": { "type": "string" },
                        "source": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Semantic memory graph" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/resources/commitment/reason": {
      "post": {
        "summary": "Reason about scarce resources against explicit commitments",
        "description": "Commitment-Aware Resource Reasoner. Supply scarce resource pools, proposed actions, explicit commitments, hidden-obligation context, decision questions, and drift events; ORI returns resource reality, protected commitments, affected commitments, tradeoff options, least-disruptive repair, non-shaming permission language, memory seeds, and Memory/Chronos/WorkGraph/Temporal/Intent/Behavior hints. Product clients still own source-of-truth resource records, payment/bank/account sync, approvals, scheduling, notifications, and regulated financial/legal/tax/debt/investment decisions.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "home" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "surface": { "type": "string", "example": "home" },
                  "context": { "type": "string", "example": "household monthly plan" },
                  "decision_question": { "type": "string", "example": "Can we do takeout tonight?" },
                  "proposed_action": {
                    "type": "object",
                    "properties": {
                      "title": { "type": "string", "example": "Takeout tonight" },
                      "resource_type": { "type": "string", "example": "money" },
                      "amount": { "type": "number", "example": 45 },
                      "capacity": { "type": "integer", "example": 60 },
                      "due_window": { "type": "string" },
                      "why": { "type": "string" }
                    }
                  },
                  "resource_pools": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "type": { "type": "string", "example": "money" },
                        "label": { "type": "string", "example": "discretionary buffer" },
                        "owner": { "type": "string" },
                        "amount": { "type": "number" },
                        "capacity": { "type": "integer" },
                        "unit": { "type": "string", "example": "usd" },
                        "confidence": { "type": "number" },
                        "source": { "type": "string" },
                        "protected": { "type": "boolean" }
                      }
                    }
                  },
                  "commitments": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": { "type": "string" },
                        "title": { "type": "string", "example": "rent" },
                        "resource_type": { "type": "string", "example": "money" },
                        "claim": { "type": "number" },
                        "capacity": { "type": "integer" },
                        "due_window": { "type": "string" },
                        "priority": { "type": "string", "example": "critical" },
                        "flexibility": { "type": "string", "example": "fixed" },
                        "owner": { "type": "string" },
                        "recurrence": { "type": "string" },
                        "provenance": { "type": "string" },
                        "emotional_weight": { "type": "string" },
                        "tags": { "type": "array", "items": { "type": "string" } }
                      }
                    }
                  },
                  "drift_event": {
                    "type": "object",
                    "properties": {
                      "title": { "type": "string", "example": "invoice slipped" },
                      "resource_type": { "type": "string", "example": "money" },
                      "amount": { "type": "number" },
                      "capacity": { "type": "integer" },
                      "reason": { "type": "string" },
                      "time": { "type": "string" }
                    }
                  },
                  "preferences": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Commitment-aware resource reasoning plan" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/behavior/event": {
      "post": {
        "summary": "Apply a behavioral event and return reinforcement feedback",
        "description": "Applies completed, missed, deferred, or partially_completed events to supplied behavior state. Misses return recovery-first feedback rather than punishment.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "home" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "behavior_id": { "type": "string", "example": "beh_daily_walk_for_20_minutes" },
                  "behavior": { "type": "object" },
                  "event": { "type": "string", "enum": ["completed", "missed", "deferred", "partially_completed"], "example": "missed" },
                  "context": {
                    "type": "object",
                    "properties": {
                      "energy": { "type": "string", "example": "low" },
                      "location": { "type": "string" },
                      "notes": { "type": "string" }
                    }
                  },
                  "prior_state": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Behavior event feedback" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/behavior/state": {
      "post": {
        "summary": "Compute behavioral state from supplied events",
        "description": "Stateless state computation for a behavior and optional event list. Returns streak, stability score, completion/miss/defer counts, friction pattern, reinforcement tier, and next best action.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "X-Ori-Context", "in": "header", "required": false, "schema": { "type": "string", "example": "dev" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "behavior_id": { "type": "string" },
                  "behavior": { "type": "object" },
                  "events": { "type": "array", "items": { "type": "object" } },
                  "state": { "type": "object" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Computed behavior state" },
          "400": { "description": "Malformed request" },
          "401": { "description": "Missing or invalid runtime key" },
          "403": { "description": "Valid key without required runtime scope" }
        }
      }
    },
    "/sovereign/identity": {
      "get": {
        "summary": "Get sovereign identity / active profile",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Current identity profile" } }
      },
      "put": {
        "summary": "Update sovereign identity / active profile",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Updated" } }
      }
    },
    "/enterprise/learn": {
      "post": {
        "summary": "Start an enterprise knowledge ingest job",
        "description": "Namespace-isolated RAG ingest for SMB tenants.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Job queued", "content": { "application/json": { "schema": { "type": "object", "properties": { "job_id": { "type": "string" } } } } } } }
      }
    },
    "/enterprise/learn/{job_id}": {
      "get": {
        "summary": "Get enterprise ingest job status",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "job_id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Job status" } }
      }
    },
    "/enterprise/knowledge/search": {
      "get": {
        "summary": "Search enterprise knowledge",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "q", "in": "query", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Search results" } }
      }
    },
    "/enterprise/knowledge": {
      "delete": {
        "summary": "Clear enterprise knowledge namespace",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Cleared" } }
      }
    },
    "/spaces": {
      "get": {
        "summary": "List spaces",
        "description": "List named project containers for the authenticated tenant. Requires runtime:spaces scope.",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Space list" } }
      },
      "post": {
        "summary": "Create a space",
        "description": "Creates a new tenant-scoped project space. Requires runtime:spaces scope.",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name"],
                "properties": {
                  "name": { "type": "string" },
                  "description": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Space created" } }
      }
    },
    "/spaces/{id}": {
      "delete": {
        "summary": "Delete a space",
        "description": "Requires runtime:spaces scope.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Deleted" } }
      }
    },
    "/spaces/{id}/documents": {
      "post": {
        "summary": "Upload a document to a space",
        "description": "Requires runtime:spaces scope.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "multipart/form-data": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Document uploaded to space" } }
      },
      "get": {
        "summary": "List documents in a space",
        "description": "Requires runtime:spaces scope.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Document list" } }
      }
    },
    "/sessions": {
      "get": {
        "summary": "List chat sessions",
        "description": "Surface-scoped session list. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "surface", "in": "query", "schema": { "type": "string", "enum": ["studio", "dev", "home", "android", "mobile"] } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } }
        ],
        "responses": { "200": { "description": "Session list, newest first" } }
      }
    },
    "/sessions/{id}/messages": {
      "get": {
        "summary": "Get session message thread",
        "description": "Full message thread for a session. Requires runtime:chat scope.",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 200 } }
        ],
        "responses": { "200": { "description": "Message thread" } }
      }
    },
    "/images/generations": {
      "post": {
        "summary": "Generate an image",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["prompt"],
                "properties": {
                  "prompt": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Generated image" } }
      }
    },
    "/daemons": {
      "get": {
        "summary": "Daemon health status",
        "description": "Returns health status of active ORI background daemons.",
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "Daemon health map" } }
      }
    },
    "/pad/dispatch": {
      "post": {
        "summary": "Parallel Agent Dispatch — fan-out",
        "description": "Dispatch a batch of independent agent tasks in parallel. ORI executes each concurrently and collects results into a PAD session.",
        "tags": ["Parallel Agent Dispatch"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["tasks"],
                "properties": {
                  "tasks": {
                    "type": "array",
                    "description": "List of agent tasks to execute in parallel.",
                    "items": {
                      "type": "object",
                      "required": ["goal"],
                      "properties": {
                        "goal": { "type": "string", "description": "Natural-language task description." },
                        "profile": { "type": "string", "description": "Optional working style profile." }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "PAD session created with task results." },
          "401": { "description": "Unauthorized.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
          "403": { "description": "Forbidden — insufficient scope.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/pad/sessions": {
      "get": {
        "summary": "List PAD sessions",
        "tags": ["Parallel Agent Dispatch"],
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Array of PAD sessions." },
          "401": { "description": "Unauthorized.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/pad/sessions/{id}": {
      "get": {
        "summary": "Get PAD session results",
        "tags": ["Parallel Agent Dispatch"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "PAD session with per-task results." },
          "404": { "description": "Session not found.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/pad/stats": {
      "get": {
        "summary": "PAD throughput metrics",
        "tags": ["Parallel Agent Dispatch"],
        "security": [{ "bearerAuth": [] }],
        "responses": { "200": { "description": "PAD throughput and latency metrics." } }
      }
    },
    "/sovereign/goals": {
      "get": {
        "summary": "List sovereign goals",
        "description": "Returns all tick-controlled sovereign agent goals for the authenticated tenant.",
        "tags": ["Sovereign Goals"],
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "Array of sovereign goals." },
          "401": { "description": "Unauthorized.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      },
      "post": {
        "summary": "Create a sovereign goal",
        "description": "Create a tick-controlled agent goal. Execution is paused between ticks — call POST /sovereign/goals/:id/tick to advance.",
        "tags": ["Sovereign Goals"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["goal"],
                "properties": {
                  "goal": { "type": "string", "description": "Natural-language goal description." },
                  "max_steps": { "type": "integer", "description": "Maximum number of execution steps.", "default": 10 }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Sovereign goal created." },
          "401": { "description": "Unauthorized.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/sovereign/goals/{id}": {
      "get": {
        "summary": "Get sovereign goal state",
        "tags": ["Sovereign Goals"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Sovereign goal state and step history." },
          "404": { "description": "Goal not found.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      },
      "delete": {
        "summary": "Cancel a sovereign goal",
        "tags": ["Sovereign Goals"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Goal cancelled." },
          "404": { "description": "Goal not found.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },
    "/sovereign/goals/{id}/tick": {
      "post": {
        "summary": "Tick a sovereign goal",
        "description": "Advance a tick-controlled sovereign goal by exactly one execution step. Returns the step result and updated goal state.",
        "tags": ["Sovereign Goals"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Step result and updated goal state." },
          "404": { "description": "Goal not found.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
        }
      }
    },

    "/tasks": {
      "post": {
        "summary": "Create a task",
        "description": "Create a persistent task with optional inline steps. Tasks are tenant-scoped and persist across sessions.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreateTaskRequest" } } }
        },
        "responses": {
          "201": { "description": "Created task with steps." },
          "400": { "description": "Invalid request body." }
        }
      },
      "get": {
        "summary": "List tasks",
        "description": "List tasks for the authenticated tenant. Supports filtering by status, surface, and session_id.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "status", "in": "query", "schema": { "type": "string", "enum": ["pending","running","done","failed","cancelled"] } },
          { "name": "surface", "in": "query", "schema": { "type": "string" } },
          { "name": "session_id", "in": "query", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "default": 0 } }
        ],
        "responses": { "200": { "description": "tasks array and count." } }
      }
    },
    "/tasks/{id}": {
      "get": {
        "summary": "Get a task",
        "description": "Fetch a task by ID including all steps.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Task with steps." }, "404": { "description": "Not found." } }
      },
      "patch": {
        "summary": "Update a task",
        "description": "Patch title, description, status, priority, or surface.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Updated task." } }
      },
      "delete": {
        "summary": "Delete a task",
        "description": "Delete a task and all its steps (cascade).",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Deleted confirmation." } }
      }
    },
    "/tasks/{id}/steps": {
      "post": {
        "summary": "Add a step to a task",
        "description": "Append a new step to an existing task.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreateStepRequest" } } } },
        "responses": { "201": { "description": "Created step." } }
      }
    },
    "/tasks/{id}/steps/{step_id}": {
      "patch": {
        "summary": "Update a step",
        "description": "Update a step's status and result.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "step_id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "status": { "type": "string" }, "result": { "type": "string" } } } } } },
        "responses": { "200": { "description": "Updated." } }
      },
      "delete": {
        "summary": "Remove a step",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "step_id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "Deleted." } }
      }
    },
    "/tasks/{id}/execute": {
      "post": {
        "summary": "Execute a task",
        "description": "Run the task's step DAG. Set Accept: text/event-stream for SSE streaming of step updates. Each SSE event carries step_id, status, and an optional snippet. Final event carries done: true and the full task object.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": {
          "200": { "description": "Task result (JSON) or SSE stream." }
        }
      },
      "get": {
        "summary": "Get execution status",
        "description": "Returns the current task state without triggering execution.",
        "tags": ["Tasks"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Task with current step statuses." } }
      }
    },

    "/entities": {
      "post": {
        "summary": "Upsert an entity",
        "description": "Create or update a named real-world entity (person, vendor, business, etc.). Used to build the relational context graph for Deep Context retrieval.",
        "tags": ["Entities"],
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UpsertEntityRequest" } } } },
        "responses": { "200": { "description": "Entity." } }
      },
      "get": {
        "summary": "List / search entities",
        "description": "List entities for the tenant. Use search= for name/alias substring match, kind= to filter by type.",
        "tags": ["Entities"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "search", "in": "query", "schema": { "type": "string" } },
          { "name": "kind", "in": "query", "schema": { "type": "string", "enum": ["person","business","vendor","account","unknown"] } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50 } }
        ],
        "responses": { "200": { "description": "entities array and count." } }
      }
    },
    "/entities/{id}": {
      "get": {
        "summary": "Get entity with event history",
        "description": "Returns the entity and its full timestamped event history — the basis for Ghost-Logistics and Deep Context recall.",
        "tags": ["Entities"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "event_limit", "in": "query", "schema": { "type": "integer", "default": 50 } }
        ],
        "responses": { "200": { "description": "entity object + events array." } }
      }
    },
    "/entities/{id}/events": {
      "post": {
        "summary": "Record an entity event",
        "description": "Append a timestamped event (message, invoice, booking, call, note) to an entity's history. These accumulate to power relational recall.",
        "tags": ["Entities"],
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CreateEntityEventRequest" } } } },
        "responses": { "201": { "description": "Created event." }, "404": { "description": "Entity not found." } }
      }
    }
  }
}
