Skip to main content

StdioRpcClient

Struct StdioRpcClient 

Source
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

Source

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).

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more