|
| 1 | +# Architecture |
| 2 | + |
| 3 | +## Transport and Backend Model |
| 4 | + |
| 5 | +The SDK supports two built-in execution backends: |
| 6 | + |
| 7 | +1. `exec` backend (`codex exec`) |
| 8 | +2. `app-server` backend (`codex app-server`) |
| 9 | + |
| 10 | +## Backend Routing Rules |
| 11 | + |
| 12 | +- `Query(...)` auto-selects backend from enabled options. |
| 13 | + - Uses `exec` when all selected options are supported there. |
| 14 | + - Routes to `app-server` when required by selected options. |
| 15 | +- `QueryStream(...)` uses app-server semantics unless `WithTransport(...)` injects custom transport. |
| 16 | +- `Client.Start(...)` uses app-server transport semantics. |
| 17 | + |
| 18 | +Capability selection/validation logic lives in: |
| 19 | + |
| 20 | +- `internal/config/capability.go` |
| 21 | + |
| 22 | +## High-Level Components |
| 23 | + |
| 24 | +- `query.go`: one-shot and query-stream orchestration |
| 25 | +- `client.go` + `client_impl.go`: stateful client interface + implementation |
| 26 | +- `with_client.go`: lifecycle helper wrapper |
| 27 | +- `mcp.go`: `Tool` interface and `NewTool` constructor for SDK-defined tools |
| 28 | +- `internal/subprocess/`: process and app-server adapters |
| 29 | +- `internal/protocol/`: JSON-RPC/session controller, dynamic tool dispatch |
| 30 | +- `internal/message/`: parsing + public message mapping |
| 31 | +- `internal/config/`: options, `DynamicTool` type, and backend capability policy |
| 32 | +- `internal/session/`: SQLite-based session metadata lookup |
| 33 | +- `internal/mcp/`: MCP server integration and status |
| 34 | + |
| 35 | +## Change Impact Guidance |
| 36 | + |
| 37 | +When changing options, transport, or session behavior: |
| 38 | + |
| 39 | +- verify backend capability mapping in `internal/config/capability.go` |
| 40 | +- update related tests (capability, query/client behavior) |
| 41 | +- keep docs aligned (`README.md`, package docs, CLAUDE rules where needed) |
0 commit comments