Skip to content

cleanup and refactor the API#16

Merged
nikomatsakis merged 10 commits intoagentclientprotocol:mainfrom
nikomatsakis:main
Nov 8, 2025
Merged

cleanup and refactor the API#16
nikomatsakis merged 10 commits intoagentclientprotocol:mainfrom
nikomatsakis:main

Conversation

@nikomatsakis
Copy link
Contributor

It is not designed to be more composable and better support trees of composers without copying around bytestreams.

nikomatsakis and others added 10 commits November 5, 2025 07:40
- Add outgoing_protocol_actor: converts OutgoingMessage → jsonrpcmsg::Message
- Add transport_outgoing_actor: serializes jsonrpcmsg::Message → bytes
- Add incoming_protocol_actor: routes jsonrpcmsg::Message to handlers/replies
- Add transport_incoming_actor: parses bytes → jsonrpcmsg::Message
- Update serve() to use split actors with intermediate channels
- Remove old monolithic incoming_actor and outgoing_actor
- Keep dispatch_request as shared helper function
- All tests pass - no API changes, refactored internals only

This is Phase 2 of the pluggable transport refactoring. Protocol layer
now handles JSON-RPC semantics (IDs, correlation) while transport layer
handles serialization/deserialization. Clear boundary at jsonrpcmsg::Message.

Co-authored-by: Claude <claude@anthropic.com>
- Add comment explaining response with id: None (error notifications)
- Remove '(Phase 2)' reference from code comments
- Keep phase tracking in PLAN.md only

Co-authored-by: Claude <claude@anthropic.com>
- Add IntoJrConnectionTransport trait for pluggable transports
- Create ByteStreamTransport struct for byte stream I/O
- Export both from crate root
- Update actor signatures to take owned values for 'static lifetime
- Fix transport_incoming_actor to clone JrConnectionCx
- All tests pass (unit + doc tests)

This enables different transport mechanisms while maintaining the same
protocol layer. ByteStreamTransport provides the default implementation
for AsyncRead + AsyncWrite streams.

Part of Phase 3: Transport trait introduction.

Co-authored-by: Claude <claude@anthropic.com>
- Remove unnecessary Unpin bounds from all transport types
  - AsyncRead/AsyncWrite traits already handle pinning internally
  - Simplifies method signatures throughout the codebase

- Make AcpAgent implement IntoJrTransport directly
  - Eliminates need for JrConnectionExt trait
  - Simpler API: pass AcpAgent directly as transport
  - Automatic child process lifecycle management

- Inline transport creation in examples and doctests
  - More readable and idiomatic code
  - Reduces variable declaration overhead

- Add MockTransport helper for doctests
  - Implements IntoJrTransport but panics if used
  - Allows doctests to compile without real I/O

BREAKING CHANGE: JrConnection::new() no longer takes byte stream arguments.
Use .serve(transport) or .with_client(transport, ...) instead.
BREAKING CHANGE: JrConnectionExt trait removed. AcpAgent now implements
IntoJrTransport and can be passed directly as a transport.
`chain_handler` now takes that
Add convenience methods to simplify the most common usage patterns:

- JrHandlerChain::serve(transport) - shorthand for connect_to(transport)?.serve().await
- JrHandlerChain::serve_with(transport, main_fn) - shorthand for connect_to(transport)?.with_client(main_fn).await
- Conductor::run(transport) - shorthand for into_handler_chain().connect_to(transport)?.serve().await

These reduce boilerplate and make the API more ergonomic for typical use cases.

Co-authored-by: Claude <claude@anthropic.com>
- Export JrConnection from lib.rs public API
- Rename ViaBytes to ByteStreams in all doctests
- Update JrConnection::new() to JrHandlerChain::new()
- Fix .with_client() examples to use .connect_to() first
- Add comprehensive docs and examples for spawn_connection()
- Update forward_to_request_cx doctest to show proper proxy pattern
- Add missing documentation for JrConnection struct
- Fix describe_chain() implementation in conductor (was todo!())

All workspace doctests now pass.

Co-authored-by: Claude <claude@anthropic.com>
@nikomatsakis nikomatsakis merged commit 946abfd into agentclientprotocol:main Nov 8, 2025
1 check passed
@nikomatsakis nikomatsakis mentioned this pull request Nov 8, 2025
This was referenced Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant