diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.md index 2efd52a0f..3ec5b4517 100644 --- a/codex-rs/app-server/README.md +++ b/codex-rs/app-server/README.md @@ -2,6 +2,16 @@ `codex app-server` is the interface Codex uses to power rich interfaces such as the [Codex VS Code extension](https://marketplace.visualstudio.com/items?itemName=openai.chatgpt). The message schema is currently unstable, but those who wish to build experimental UIs on top of Codex may find it valuable. +## Table of Contents +- [Protocol](#protocol) +- [Message Schema](#message-schema) +- [Lifecycle Overview](#lifecycle-overview) +- [Initialization](#initialization) +- [Core primitives](#core-primitives) +- [Thread & turn endpoints](#thread--turn-endpoints) +- [Auth endpoints](#auth-endpoints) +- [Events (work-in-progress)](#v2-streaming-events-work-in-progress) + ## Protocol Similar to [MCP](https://modelcontextprotocol.io/), `codex app-server` supports bidirectional communication, streaming JSONL over stdio. The protocol is JSON-RPC 2.0, though the `"jsonrpc":"2.0"` header is omitted. @@ -15,6 +25,14 @@ codex app-server generate-ts --out DIR codex app-server generate-json-schema --out DIR ``` +## Lifecycle Overview + +- Initialize once: Immediately after launching the codex app-server process, send an `initialize` request with your client metadata, then emit an `initialized` notification. Any other request before this handshake gets rejected. +- Start (or resume) a thread: Call `thread/start` to open a fresh conversation. The response returns the thread object and you’ll also get a `thread/started` notification. If you’re continuing an existing conversation, call `thread/resume` with its ID instead. +- Begin a turn: To send user input, call `turn/start` with the target `threadId` and the user's input. Optional fields let you override model, cwd, sandbox policy, etc. This immediately returns the new turn object and triggers a `turn/started` notification. +- Stream events: After `turn/start`, keep reading JSON-RPC notifications on stdout. You’ll see `item/started`, `item/completed`, deltas like `item/agentMessage/delta`, tool progress, etc. These represent streaming model output plus any side effects (commands, tool calls, reasoning notes). +- Finish the turn: When the model is done (or the turn is interrupted via making the `turn/interrupt` call), the server sends `turn/completed` with the final turn state and token usage. + ## Initialization Clients must send a single `initialize` request before invoking any other method, then acknowledge with an `initialized` notification. The server returns the user agent string it will present to upstream services; subsequent requests issued before initialization receive a `"Not initialized"` error, and repeated `initialize` calls receive an `"Already initialized"` error. @@ -258,3 +276,33 @@ Field notes: - `codex app-server generate-ts --out