pub struct StdioRpcClient { /* private fields */ }Expand description
A JSON-RPC 2.0 client over a spawned tcode serve --stdio child.
Why: see module docs.
What: owns the child + its stdin/stdout handles and a monotonic request
id counter; buffers notification lines encountered while a call is
awaiting its own response so nothing observed on the wire is ever
silently dropped.
Test: tests::* for the pure helpers; tests/cli_e2e.rs for the real
spawn + wire round trip.
Implementations§
Source§impl StdioRpcClient
impl StdioRpcClient
Sourcepub fn spawn(tcode_exe: &Path, project: &Path) -> Result<Self, RpcClientError>
pub fn spawn(tcode_exe: &Path, project: &Path) -> Result<Self, RpcClientError>
Spawn <tcode_exe> serve --project <project> --stdio and return a
client wired to its stdio pipes.
Why: tcode_exe is normally std::env::current_exe() — the CLI
re-spawns ITSELF in daemon mode, per the ticket’s “in-process spawn”
requirement; passing it explicitly (rather than hardcoding
current_exe() inside this function) keeps this module testable
with an arbitrary binary path and avoids a hidden std::env read
inside library code.
What: kill_on_drop(true) so a CLI process that exits early (panic,
early return) never leaks the child; the child’s stderr is
inherited so daemon-side log lines are visible to the operator
without corrupting the stdout NDJSON framing this client reads.
Test: tests/cli_e2e.rs (spawns the real binary).
Sourcepub async fn call(
&mut self,
method: &str,
params: Value,
) -> Result<Value, RpcClientError>
pub async fn call( &mut self, method: &str, params: Value, ) -> Result<Value, RpcClientError>
Call method with params, waiting for its matching response.
Why: the request/response half of the protocol every non-streaming
subcommand (session.list/status/cancel/get_transcript,
task.run’s initial call) uses.
What: writes one NDJSON request line, then reads lines until one
carries the SAME id — any session.event notification observed
along the way is buffered (not dropped) for a later
Self::next_notification call. A JSON-RPC error envelope becomes
Err(RpcClientError::Rpc); the whole call is bounded by
DEFAULT_CALL_TIMEOUT.
Test: covered end-to-end by tests/cli_e2e.rs.
Sourcepub async fn next_notification(
&mut self,
wait: Duration,
) -> Result<Option<SessionEventEnvelope>, RpcClientError>
pub async fn next_notification( &mut self, wait: Duration, ) -> Result<Option<SessionEventEnvelope>, RpcClientError>
Return the next observed session.event notification, waiting up to
wait for a fresh one if none is already buffered.
Why: the streaming subcommands (attach, run-task) poll this in a
loop, printing each envelope as it arrives, until a terminal event or
the user interrupts.
What: drains Self::pending_notifications first (events observed
while a previous call was still awaiting its own response); only
reads fresh lines from the child when the buffer is empty.
Ok(None) means “nothing arrived within wait” — NOT connection
loss (that is Err(ConnectionClosed)) — callers should keep polling.
Test: covered end-to-end by tests/cli_e2e.rs.
Sourcepub async fn shutdown(self, grace: Duration) -> Result<(), RpcClientError>
pub async fn shutdown(self, grace: Duration) -> Result<(), RpcClientError>
Close stdin (EOF) and wait, bounded by grace, for the child to
exit cleanly; force-kills it if it doesn’t.
Why: mirrors the daemon’s own connection-safe-shutdown convention
(issue #534) from the client side — the CLI should give its spawned
child a real chance to drain before the process ends.
What: dropping stdin signals EOF (the same trigger
serve::run_stdio reacts to); force-kill is best-effort, matching
every other bounded-shutdown path in this crate.
Test: covered end-to-end by tests/cli_e2e.rs.
Auto Trait Implementations§
impl !RefUnwindSafe for StdioRpcClient
impl !UnwindSafe for StdioRpcClient
impl Freeze for StdioRpcClient
impl Send for StdioRpcClient
impl Sync for StdioRpcClient
impl Unpin for StdioRpcClient
impl UnsafeUnpin for StdioRpcClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more