pty::connect built the socket URL from the client's base URL, so after
the service restarted on a new port the ticket request followed it but
the socket went to the old port. Transport::route maps a URL to where a
request would go now; the following transport points it at the current
service, as the TS TUI rebuilds persistentPty with the new URL.
A port of packages/client/src/mcp.ts: the client answers MCP JSON-RPC
over /api/experimental/client-mcp and reconnects with backoff until the
connection closes. The tests port packages/client/test/mcp.test.ts.
Port of handlers/run.ts, run/run.ts and run/noninteractive.ts: text and
--format json output, permissions and forms auto-rejected (or approved
with --auto), -f attachments typed by the mime-types table, stdin and
words after --, -w worktrees, titles and archived sessions. Events and
messages stay JSON so JSON lines pass server fields through unchanged.
P-CLI scenarios in parity/scenarios/C.10 compare it with the TS run.
Port solid/pty.ts: decode the control messages, encode interaction frames, and connect with a ticket. A Connector opens the socket, so tests can serve a fake one.
A panic in the SSE reader ended the connection task, so the TUI silently stopped receiving events. Catch it at the stream boundary, log it, and treat it as a failed stream so the loop reconnects as after a transport error.
The reader searched the text buffer from a byte offset that could land inside a multibyte character, so a chunk ending in one panicked on the next chunk and ended live updates. Buffer raw bytes, split lines on LF, CRLF and CR bytes, and decode only complete lines, which matches the TypeScript streaming decoder.
The generated types use f64 for protocol numbers that are not integer
schemas, and serde writes a whole f64 as 3.0 where JSON.stringify writes
3. The generator now puts a serialize_with helper on every f64 field,
alias and union member, so request bodies match the TypeScript client
byte for byte. The F.2 oracle covers mention offsets and form answers.
carbon-1: a union member that is itself a union with several tags joins the
outer tag, so SessionLogItem routes log.synced to LogSynced and its tag()
delegates to the inner enum.
carbon-2: Schema.NonEmptyArray(T) is Vec<T>, so form fields and tool
content are typed (FormField, ToolContent).
carbon-3: Ref_1 twins that Rust decodes the same as Ref share its type
(FormInfo, ShellInfo, FormAnswer, the inbox payloads, message parts).
carbon-4: untagged unions get a generated Deserialize that skips a member
whose required literal field holds another value, so an LSP server entry
with disabled: false keeps its command.
carbon-5: generated errors implement TaggedError, and DeclaredError::decode
checks the tag.
Call sites in crates/store and crates/ui follow the renamed types.
Memory serves canned routes in order, streams /api/event from emit(), logs every request, and counts unread responses so a test can wait until the client is idle.
models, reload, debug agents, debug config (redacted), debug heap-dump, and debug
paths, ported from the TS handlers. Reads print the server's JSON as it came, as
the Promise client returns it, so Client::json is public. Sorting follows
localeCompare. P-CLI scenarios in parity/scenarios/C.1 pass against TS; H.3's
models case now runs for Rust too.
The generator read httpApiStatus only through resolveAt, so the 50 endpoints whose
no-content success keeps 204 on its context annotations expected 200, as
resolveHttpApiStatus in httpapi-codegen does not. Every such call (reload, session
remove, permission reply, model switch) failed against a real server with
UnexpectedStatus 204. Tests that answered those calls with 200 now answer 204.
V2Event's Event impl now folds adjacent deltas of one part (session, message, ordinal) or one tool call, so a 10 ms batch of streamed deltas reaches the store as one edit.
Session.Message.Info has a Compaction member that is itself a union tagged by status, so the generator fell back to an untagged enum. serde then decoded an assistant message as the first member that fits (AgentSelected). Nested unions now join the outer tag when all their objects share one value.
Records decoded into BTreeMap, which sorts keys. The TUI prints tool inputs in wire order (primitiveInputSummary, the fallback JSON title), so records are now IndexMap; serde_json already preserves order.
An opt-in live test (OPENCODE_LIVE=1) reads through the generated client from
the service script/live.sh uses: info, sessions, messages, inbox, forms,
permissions, location collections, and the event stream. It skips
experimental.session.stats, which took the shared service down unbounded.
A P-ORACLE fixture records the requests the TypeScript Promise client builds;
the generated Rust client must build the same ones, and query::append must
match appendQuery. Unit tests cover tagged unions (known, rpc.*, unknown),
literal enums, double options, declared errors, binary bodies, auth, and
the event stream through F.3's SSE reader.
Every endpoint's location query decoded into its own struct; equal anonymous
objects and unions now share one, and the location query is LocationQueryInput.
script/gen/api.ts compiles ClientApi with the Promise client's options and emits
types and one method per endpoint (166) into crates/api/src/generated. The
request core, errors, query encoding, and the reqwest transport are written
by hand. Tagged unions decode through a generated Deserialize that keeps
unknown members and routes rpc.* events.
Build socket URLs as the PTY and client MCP clients do (path prefix and base query kept, URLSearchParams.set order, ws or wss), with an optional ticket parameter, and open them with handshake headers.
SharedEvents ports shared-events.ts: one upstream per subscriber set, a types filter, the latest server.connected for late subscribers, and a 4,096-event cap per subscriber. connect() ports createClientConnection: server.connected first, the 2 s connect and 45 s idle limits, resync, 1 s reconnect, and 10 ms batches with adjacent deltas merged on a bounded queue. Both are generic over an Event trait. An opt-in live test (OPENCODE_LIVE=1) reads the running service.
Port Identifier.create with session, message, and part prefixes. A P-ORACLE script records the time prefixes TypeScript mints for a call sequence, counter restarts and overflow included, and the Rust test replays it.
Port the generated TypeScript client's SSE reader: blank-line blocks, joined data lines, CRLF and CR normalization across chunks, streaming UTF-8 decoding, and the 16 MiB limit counted in UTF-16 units. Every chunk reports activity, keepalive comments included.
Add packages/cli-rs: a Cargo workspace with the 14 crates of the plan,
module stubs for api, local, service, store, and ui, and the expected
third-party crates in [workspace.dependencies]. opentui is a path
dependency on the local opentui-rust checkout, linked statically.
script/opentui-lib.sh copies native artifacts whose header matches the
bindings into ~/.cache/opencode-rs/opentui, where .cargo/config.toml
points OPENTUI_LIB_DIR. opencode-rs --version runs; script/live.sh
runs it against the elected background service.