Commit graph

25 commits

Author SHA1 Message Date
Simon Klee
e3b044de70
fix(cli-rs): open the terminal socket at the restarted service
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.
2026-11-05 00:34:34 +01:00
Simon Klee
d77526b247
chore(cli-rs): format the composer and client MCP files 2026-11-05 00:08:20 +01:00
Simon Klee
b813d593c2
feat(cli-rs): add the client MCP socket
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.
2026-11-05 00:08:20 +01:00
Simon Klee
ff7fa63d0d
feat(cli-rs): add the run command
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.
2026-11-04 23:46:40 +01:00
Simon Klee
16f5d5e026
feat(cli-rs): add the persistent PTY socket protocol and connector
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.
2026-11-04 22:08:27 +01:00
Simon Klee
9229f43da3
fix(cli-rs): reconnect the event stream after a reader panic
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.
2026-11-04 21:07:49 +01:00
Simon Klee
4768bb2329
fix(cli-rs): split SSE lines on bytes so a split code point cannot panic
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.
2026-11-04 21:07:49 +01:00
Simon Klee
ce0c29bcd7
fix(cli-rs): write whole numbers as integers in request bodies
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.
2026-11-04 20:58:23 +01:00
Simon Klee
0f7d1bd7b4
test(cli-rs): read session logs in the live API test
Each of the newest sessions' log is read from the start without following;
every item must decode as a durable event or log.synced, none unknown.
2026-11-04 19:51:14 +01:00
Simon Klee
26cfacbbf9
fix(cli-rs): fix the API types carbon found wrong in F.2
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.
2026-11-04 19:51:14 +01:00
Simon Klee
7c42913496
feat(cli-rs): add the in-memory transport for P-APP
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.
2026-11-04 19:29:11 +01:00
Simon Klee
6fa6bdf1a1
feat(cli-rs): add models, reload, and the debug commands
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.
2026-11-04 19:18:32 +01:00
Simon Klee
a15b60f360
fix(cli-rs): expect 204 from no-content endpoints
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.
2026-11-04 19:17:11 +01:00
Simon Klee
08f517b0ee
feat(cli-rs): merge adjacent text, reasoning, and tool input deltas
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.
2026-11-04 18:48:52 +01:00
Simon Klee
d6a1d29a68
fix(cli-rs): tag message unions whose members are unions
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.
2026-11-04 18:48:51 +01:00
Simon Klee
7baefa3f36
fix(cli-rs): keep JSON key order in generated records
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.
2026-11-04 18:34:12 +01:00
Simon Klee
b826557733
test(cli-rs): decode the TUI's reads against the running service
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.
2026-11-04 18:20:48 +01:00
Simon Klee
34e9ec7d47
test(cli-rs): prove API requests and decoding against the TS client
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.
2026-11-04 18:20:48 +01:00
Simon Klee
a477234497
feat(cli-rs): share one type for equal anonymous API shapes
Every endpoint's location query decoded into its own struct; equal anonymous
objects and unions now share one, and the location query is LocationQueryInput.
2026-11-04 18:20:48 +01:00
Simon Klee
cc409d1fcf
feat(cli-rs): generate the Rust API client from ClientApi
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.
2026-11-04 18:20:48 +01:00
Simon Klee
e812746abe
feat(cli-rs): add the WebSocket helper
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.
2026-11-04 18:04:23 +01:00
Simon Klee
e5800a0de2
feat(cli-rs): share event streams and run the connection loop
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.
2026-11-04 18:04:18 +01:00
Simon Klee
00695b7119
feat(cli-rs): mint time-sortable identifiers
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.
2026-11-04 18:04:13 +01:00
Simon Klee
3d6ee48b53
feat(cli-rs): add the SSE reader
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.
2026-11-04 18:04:08 +01:00
Simon Klee
271fc7c26d
feat(cli-rs): scaffold the Rust client workspace
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.
2026-11-04 17:52:34 +01:00