| 1 | # Codewhale App Server protocol |
| 2 | |
| 3 | This crate owns the existing Runtime image, event-envelope, capability and |
| 4 | dynamic-tool contracts, plus the shared RPC envelope and initialization shapes. |
| 5 | Engine, App Server, hooks and the SDK consume that one |
| 6 | family; the former `codewhale_protocol::runtime` module is removed. |
| 7 | |
| 8 | The runtime contracts reuse serde and the existing workspace Chrono dependency. The optional `schema` feature uses |
| 9 | the existing locked schemars dependency and shared JSON Schema to TypeScript |
| 10 | renderer. It selects input/output schema contracts from the actual owner. Runtime output |
| 11 | fields reflect serialization while accepted input defaults stay optional. |
| 12 | DynamicToolSpecOutput is the serialized view of the same DynamicToolSpec Rust |
| 13 | type used in thread-created output. Runtime TypeScript uses JSON-serializable |
| 14 | object members (which may omit undefined values); root/array undefined remains |
| 15 | excluded. The existing Native host generator keeps its prior text and |
| 16 | present-value normalization. |
| 17 | |
| 18 | Generate outputs with: |
| 19 | |
| 20 | ```sh |
| 21 | cargo run -p codewhale-app-server-protocol --features schema --bin codewhale-app-server-schema -- --write |
| 22 | ``` |
| 23 | |
| 24 | The command writes `schema/json/runtime.schema.json`, |
| 25 | `schema/typescript/runtime.d.ts`, and the matching packaged SDK declaration. |
| 26 | `--check` compares all three without writing. Normal runtime startup does not |
| 27 | generate files or enable schema machinery. |
| 28 | |
| 29 | `contract/codex-v2.json` is the frozen, versioned Codex v2 contract manifest: |
| 30 | every pinned stable Codex method with its tier (A, B, C or undecided), status, |
| 31 | basis and, for selected methods, the upstream variant, params and result types; |
| 32 | the dispatch rule for each tier; the error codes; and the Codewhale extensions. |
| 33 | `src/codegen` reads it with the unmodified pinned export and writes |
| 34 | `src/methods.rs`, `src/v2.rs`, `METHODS.md`, |
| 35 | `schema/json/codex-v2.schema.json` and `schema/typescript/codex-v2.d.ts`: |
| 36 | |
| 37 | ```sh |
| 38 | cargo run -p codewhale-app-server-protocol --bin codewhale-codex-contract -- --write |
| 39 | ``` |
| 40 | |
| 41 | `--check` compares without writing, and `tests/contract.rs` fails on any drift, |
| 42 | on any disagreement between the manifest and the pinned method sets, and on |
| 43 | any selected shape whose typed Rust value does not round-trip an instance the |
| 44 | pinned schema accepts. `v2::ClientRequestParams`, `v2::ServerNotification`, |
| 45 | `v2::ServerRequestParams`, `v2::ClientResponse` and `v2::ServerRequestResponse` |
| 46 | are the typed envelopes; Codex envelopes carry no `jsonrpc` member. A typed |
| 47 | shape is not a handler: `METHODS.md` status says what main dispatches. |
| 48 | |
| 49 | The selected future Codex wire target is official `rust-v0.166.0`, commit |
| 50 | `6ff1e1ca3b30fc8b914720681fcf5fe62e95f856`. Its four-variant envelope and initialize/initialized lifecycle serve JSONL |
| 51 | stdio and WebSocket text messages over the private owner channel. The private |
| 52 | framing retains kernel peer and attach checks, bounded headers and messages, and |
| 53 | ACP's separate JSON-RPC 2.0 envelope. TCP WebSocket listener, exact thread/turn/item |
| 54 | dispatch, subscriptions, interactions and their complete generated SDK remain separate required adoption |
| 55 | slices; legacy compatibility methods do not establish full Codex wire parity. |
| 56 | The existing Runtime journal and native Engine receipt/store authority remain |
| 57 | where they are; no serialized observation creates publication authority. |
| 58 |